我有一個SQL設置用於查詢數據庫並查找表中的金額總和,但它不返回任何內容,所有數據字段都是正確的,查詢在運行方式上是正確的,我認爲問題是將它傳遞給數據讀取器的變量,如果任何人都可以糾正這個問題,我會非常感激。變量沒有從SQl查詢中獲取數據
這是代碼,我認爲這是值得做的的DataReader:
System.Web.Services.Protocols.SoapException:服務器無法處理請求。 ---
System.Data.OleDb.OleDbException:FROM子句中的語法錯誤。在System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult在 System.Data.OleDb.OleDbCommand.ExecuteCommandText(對象& 的ExecuteReuslt)在 System.Data.OleDb.OleDbCommand.ExecuteCommand(的CommandBehavior (tagDBPARAMS dbParams,對象&的ExecuteReuslt)行爲,在 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(的CommandBehavior 行爲,字符串方法)對象&的ExecuteReuslt)在 System.Data.OleDb.OleDbCommand.ExecuteReader(的CommandBehavior行爲) 在HSBC.CheckBal(Int64的ACCOUNTNUMBER)在HSBC.CheckBalance(Int64 accountnumber)---內部異常堆棧tra結束ce ---
描述:在執行 當前Web請求期間發生未處理的異常。請查看堆棧跟蹤以獲取有關該錯誤的更多信息以及源代碼的位置。
異常詳細信息:System.Web.Services.Protocols.SoapException: System.Web.Services.Protocols.SoapException:服務器無法對 進程請求。 ---> System.Data.OleDb.OleDbException:FROM子句中的語法錯誤 。在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult在 System.Data.OleDb.OleDbCommand.ExecuteCommandText(對象& 的ExecuteReuslt)在 System.Data.OleDb.OleDbCommand.ExecuteCommand(的CommandBehavior(tagDBPARAMS dbParams,對象&的ExecuteReuslt) 行爲,在 System.Data.OleDb.OleDbCommand.ExecuteReader(的CommandBehavior行爲) 對象在 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(的CommandBehavior 行爲,字符串方法)&的ExecuteReuslt)在HSBC.CheckBal(的Int64 ACCOUNTNUMBER)在HSBC.CheckBalance(Int64 賬號)---客棧結束er異常棧跟蹤---
這是被調用的代碼。
'Creates a service web method
Private Function CheckBal(ByVal accountnumber As Long) As String
'Database(drivers, connections And commands)
Dim BalanceDr As OleDbDataReader
Dim BalanceConn As OleDbConnection
Dim BalanceCmd As OleDbCommand
'Database connection string
Dim Connx As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("../database/HSBC.mdb") & ";"
'SQL
Dim SQL As String = "SELECT Transaction_Amount FROM Transaction WHERE Account_Number =" & accountnumber & ";"
Dim bal As String
'Open the connection to the database
BalanceConn = New OleDbConnection(Connx)
BalanceConn.Open()
BalanceCmd = New OleDbCommand(SQL, BalanceConn)
'Create a DataReader that will return information.
BalanceDr = _
BalanceCmd.ExecuteReader(CommandBehavior.CloseConnection)
If BalanceDr.Read() Then
'A row was returned
bal = BalanceDr(0)
Else
'A row was not returned
bal = "No Balance For Account Found"
End If
BalanceDr.Close()
Return SQL
End Function
End Class
並應用對數據庫文件夾的寫權限?沒有它,它不能創建.ldb文件,因此沒有鎖,沒有訪問沒有查詢沒有什麼。雖然和打開連接後檢查/數據庫文件夾,看看ldb文件是否在那裏。如果不是,則缺少權限。如果它的網絡我不記得是否它的IIS的I_User或W_User。 – xQbert 2012-01-09 00:18:08
在權限下的數據庫中,它具有讀取設計,修改設計,管理,讀取數據,更新數據,插入數據和刪除數據的功能,但它表示它以管理員身份運行。另外,我在數據庫文件夾中沒有ldb文件。權限在那裏,因爲我有另一個服務正在保存到數據庫和一個外部數據庫 – user1134409 2012-01-09 00:23:12
.ldb文件是在連接打開時創建的。手動打開.mdb,你會看到訪問在該文件夾中創建一個.ldb。至於權限;如果這是一個網站,則需要I_USER或I_Wuser對數據庫文件夾擁有寫入權限。無論Web服務在哪個帳戶下運行,都需要對要寫入的文件夾的權限。 [示例](http://www.justskins.com/forums/web-server-permissions-for-118149.html) – xQbert 2012-01-09 00:25:38