我的Pervasive Server上有一个名为EGC_Expl_BOM_TT的存储过程,我可以在Excel的SQL查询窗口中使用“CALL EGC_Expl_BOM_TT('B-8579-K')”执行它,但它会执行该功能,然后通过我错了,迫使我退出查询窗口。我找到了以下用于执行存储过程的VBA代码。我需要帮助根据我的具体需要进行调整。我的存储过程只有一个变量输入,我将放在第1页单元格A1中。
这是我的Excel查询窗口中的连接字符串。我需要帮助在VBA代码中格式化它:
Provider = MSDASQL.1; Persist Security Info = True;扩展属性=“DSN = global_EGC; ServerName = fah2.1583; UID = UserIDName; PWD =密码; ArrayFetchOn = 1; ArrayBufferSize = 8; TransportHint = TCP; DBQ = GLOBALEGC;客户机版本= 11.31.017.000; CodePageConvert = 1252; PvClientEncoding = CP1252; PvServerEncoding = CP1252; AutoDoubleQuote = 0;“
Function Sproc()
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim cmd As ADODB.Command
Dim ConnectionString As String
Dim StrSproc As String
Set cnn = New ADODB.Connection
cnn.ConnectionString = "Provider=MSDASQL.1;DSN=global_EGC;ServerName=fah2.1583;UID=Myusername;PWD=mypassword;ArrayFetchOn=1;ArrayBufferSize=8;TransportHint=TCP;DBQ=GLOBALEGC;ClientVersion=11.31.017.000;CodePageConvert=1252;PvClientEncoding=CP1252;PvServerEncoding=CP1252;AutoDoubleQuote=0;"
'Opens connection to the database
On Error GoTo SQL_ConnectionError
cnn.Open ConnectionString
On Error GoTo 0
'Timeout error in seconds for executing the entire query; this will run for 15 minutes before VBA timesout, but your database might timeout before this value
cnn.CommandTimeout = 900
Set rst = New ADODB.Connection
StrSproc = "set nocount on; "
StrSproc = "CALL EGC_Expl_BOM_TT" + Cells(1, 1)
rst.ActiveConnection = cnn
On Error GoTo SQL_StatementError
rst.Open StrSproc
On Error GoTo 0
If Not rst.EOF And Not rst.BOF Then
Sproc = IIf(IsNull(rst.Fields(0).Value), "(BLANK)", rst.Fields(0).Value)
End If
Exit Function
SQL_ConnectionError:
MsgBox "Error connecting to the server / database. Please check the connection string."
Exit Function
SQL_StatementError:
MsgBox "Error with the SQL syntax. Please check StrSproc."
Debug.Print StrSproc
Exit Function
SQL_ConnectionError:
Msgbox "Error connecting to the server / database. Please check the connection string."
Exit Function
SQL_StatementError:
Msgbox "Error with the SQL syntax. Please check StrSproc."
Debug.Print StrSproc
Exit Function
End Function
答案 0 :(得分:0)
连接字符串类似于:
cnn.ConnectionString = "Provider=MSDASQL.1;DSN=global_EGC;ServerName=fah2.1583;UID=UserIDName;PWD=password;ArrayFetchOn=1;ArrayBufferSize=8;TransportHint=TCP;DBQ=GLOBALEGC;ClientVersion=11.31.017.000;CodePageConvert=1252;PvClientEncoding=CP1252;PvServerEncoding=CP1252;AutoDoubleQuote=0;"
你的陈述是这样的:
StrSproc = "EXEC EGC_Expl_BOM_TT" + Cells(1,1)