1
我想使用宏打开一个新的连接,但语句“Rcrdst.Open”给我运行时错误:“ORA-00911:无效字符”。任何人都可以帮我找到问题吗?使用宏连接到数据库
Dim C As Integer
Dim ambiente As String
Dim userid As String
Dim Password As String
Dim Query As String
Dim Newsht As Worksheet
Dim Conn As ADODB.Connection
Dim Rcrdst As ADODB.Recordset
Set Newsht = ActiveWorkbook.Sheets("sheet1")
ambiente = InputBox("Please insert environement in which query has to be run.", "Test")
userid = InputBox("Please insert your USER ID for " & ambiente & " environment.", "Test")
Password = InputBox("Please insert the PASSWORD related to " & userid & " user.", "Test")
If userid <> "" And Password <> "" Then
Set Conn = New ADODB.Connection
Conn.ConnectionString = "Provider=MSDAORA; Password= " & Password & ";User ID= " & userid & "; Data Source = " & ambiente & ";Persist Security Info=True"
Conn.Open
Query = "select seq_prenotazione, cod_rapporto,stato_pren from via.prenotazione where seq_prenotazione in (700016298527, 700016761977);"
Set Rcrdst = New ADODB.Recordset
Rcrdst.CursorLocation = adUseClient
Rcrdst.CursorType = adOpenStatic
Rcrdst.LockType = adLockBatchOptimistic
Rcrdst.Open Query, conn
'code to work on data extracted
end if
Rcrdst.Close
Conn.Close
在此先感谢
执行查询时出现错误,错误代码是“ORA ..”,看起来像错误是由您的数据库引发的。错误描述是_Identifiers可能不以字母和数字以外的任何ASCII字符开头。 $#\ _也允许在第一个字符之后。我猜你的'userid'和'Password'变量包含数据库无法处理的意大利unicode字符。此外,你不应该关闭你的连接,而其他对象(即'Rcrdst')依赖于它。 – BenDot
我的'userid'和'password'都只包含字母和数字,当我复制粘贴这个确切的查询在SQL开发中它完美运行。 – Srijan
我建议仔细看一下'Query'变量。与自己复制代码相比,您的代码可能会有所不同。使用Excel打印字符串或在调试模式下查看它。 – BenDot