2015-04-24 49 views
0

最近在Windows 7 Prof PC上安裝新版本的Neo4j。能夠使用API​​批量插入創建節點。 Cypher查詢從Web界面工作,但現在VB.NET代碼在評論'檢索查詢結果後將失敗,這將在JSon。這跑好上一版本的Neo4j(2.2.x以上)Neo4j 2.3.0-M01密碼從VB.NET查詢失敗

Public Shared Function DBQuery(URI As String, PostString As String) As DataView 
    'runs query and returns JSon results as a dataview 
    'Uses POST method to access Neo4j Server API 
    Dim S As String = "" 
    Dim HttpWReq As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(URI) 
    HttpWReq.Method = "POST" 
    HttpWReq.ContentType = "application/json" 
    HttpWReq.Accept = "application/json" 
    Dim B1() As Byte = System.Text.Encoding.Unicode.GetBytes(PostString, 0, Len(PostString)) 

    'POST query 
    'http://blog.micic.ch/net/using-neo4j-graph-db-with-c-net 
    HttpWReq.Connection = "Open" 
    HttpWReq.ContentLength = B1.Length 
    Dim newStream As IO.Stream = HttpWReq.GetRequestStream() 
    'this method closes stream before calling getResponse 
    Using newStream 
     newStream.Write(B1, 0, B1.Length) 
    End Using 

    'retrieve results of query, which will be in JSon 
    Dim HttpWResp As System.Net.HttpWebResponse = CType(HttpWReq.GetResponse(), System.Net.HttpWebResponse) 
    HttpWReq.KeepAlive = False 
    HttpWReq.Timeout = 15000000 

    Dim E As System.Text.Encoding = System.Text.Encoding.GetEncoding(HttpWResp.CharacterSet) 
    Dim SR As IO.StreamReader = New IO.StreamReader(HttpWResp.GetResponseStream, encoding:=E) 
    S = SR.ReadToEnd 'JSon result 
    Return JSonToDV(S) 
End Function 

的文檔V2.3.0指示不同的conf文件設置的需要,但是這是行不通的。該文檔在http://neo4j.com/docs/2.3.0-M01/server-configuration.html。 neo4j-server.properties文件最初沒有org.neo4j.server.database.location = data/graph.db的條目。添加建議的行(org.neo4j.server.database.location =「C:/Data/Neo4j/UMLS/graph.db」),然後數據庫啓動失敗。希望建議的解決方案。

+0

我收到的錯誤是InternalServerError {500}。也許這是查詢?在web界面中,這成功運行:MATCH(n:MRCONSO)其中n.SAB ='SNOMEDCT_US'RETURN n.CUI,n.STR LIMIT 25,但在我的VB.NET代碼中,它給出了服務器錯誤,正在使用{「query」:「MATCH(n:MRCONSO)where n.SAB ='SNOMEDCT_US'RETURN n.CUI,n.STR LIMIT 25」}。 –

回答

0

問題不在於Neo4j 2.3.0,而在於使用VB.NET代碼。修正後的代碼是:

Public Shared Function DBQuery(URI As String, PostString As String, method As EnumLib.WebServiceMethod) As DataView 
    'Used for individual API calls; see BulkUpload for other method 
    'Uses POST method to access Neo4j Server API 
    Dim ID As Long = 0 
    Dim HttpWReq As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(URI) 

    Select Case method 
     Case EnumLib.WebServiceMethod.POST 
      HttpWReq.Method = "POST" 
     Case EnumLib.WebServiceMethod.GET 
      HttpWReq.Method = "GET" 
    End Select 
    HttpWReq.ContentType = "application/json" 
    HttpWReq.Accept = "application/json" 

    Dim B1() As Byte = System.Text.Encoding.UTF8.GetBytes(PostString, 0, Len(PostString)) 

    'http://blog.micic.ch/net/using-neo4j-graph-db-with-c-net 
    HttpWReq.Connection = "Open" 
    Dim S As String = "" 
    Try 
     HttpWReq.ContentLength = B1.Length 
     Dim newStream As IO.Stream = HttpWReq.GetRequestStream() 
     'this method closes stream before calling getResponse 
     Using newStream 
      newStream.Write(B1, 0, B1.Length) 
     End Using 

     Dim HttpWResp As System.Net.HttpWebResponse = CType(HttpWReq.GetResponse(), System.Net.HttpWebResponse) 

     Dim E As System.Text.Encoding = System.Text.Encoding.GetEncoding(HttpWResp.CharacterSet) 
     Dim SR As IO.StreamReader = New IO.StreamReader(HttpWResp.GetResponseStream, encoding:=E) 
     S = SR.ReadToEnd 

    Catch ex As System.Net.WebException 
     MsgBox("Message: " & vbLf & ex.Message) 
     Dim RS As IO.StreamReader = New IO.StreamReader(ex.Response.GetResponseStream) 
     Dim SS As String = RS.ReadToEnd 
     PostReturnString = "WebException Error: " & ex.Message & vbLf & vbLf & ex.Status & vbLf & vbLf & SS 
     ' MsgBox("Status: " & vbLf & ex.Status & vbLf & vbLf & SS) 
    End Try 
    Return JSonToDV(S) 
    End Function