简单的任务:连接到数据库,执行存储过程,断开连接

发布于 2024-11-06 23:44:07 字数 197 浏览 7 评论 0原文

我不一定需要从 VBScript 向存储过程传递任何变量,我只需要在服务器上运行存储过程。我还没有找到任何明确的示例来说明如何执行此操作,只有很多人解释如何将变量从 SP 传递回 VBScript。

任何帮助将不胜感激!看起来我必须打开一个连接,然后发送命令来执行存储过程,然后关闭连接,但我对如何从 VBscript 执行此操作有点迷失。

谢谢!

I don't necessarily need to pass the stored procedures any variables from my VBScript, I just need to run the stored procedure on the server. I haven't been able to find any clear examples of how to do this—just a lot of people explaining how to pass a variable from a SP back to a VBScript.

Any help would be so appreciated! It looks like I'll have to open a connection, then send the command to execute the stored procedure, then close the connection, but I'm a bit lost about how to do this from a VBscript.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薄荷→糖丶微凉 2024-11-13 23:44:07

您可以使用 ADODB.Connection 来自 VbScript 的对象

检查此示例

Dim sServer, sConn, oConn, sDatabaseName, sUser, sPassword
sDatabaseName="test"
sServer="localhost"
sUser="sa"
sPassword="yourpassword"
sConn="provider=sqloledb;data source=" & sServer & ";initial catalog=" & sDatabaseName

Set oConn = CreateObject("ADODB.Connection")
oConn.Open sConn, sUser, sPassword
oConn.Execute "exec sp_help"

WScript.Echo "executed"
oConn.Close
Set oConn = Nothing

you can use the ADODB.Connection object from VbScript

check this sample

Dim sServer, sConn, oConn, sDatabaseName, sUser, sPassword
sDatabaseName="test"
sServer="localhost"
sUser="sa"
sPassword="yourpassword"
sConn="provider=sqloledb;data source=" & sServer & ";initial catalog=" & sDatabaseName

Set oConn = CreateObject("ADODB.Connection")
oConn.Open sConn, sUser, sPassword
oConn.Execute "exec sp_help"

WScript.Echo "executed"
oConn.Close
Set oConn = Nothing
汹涌人海 2024-11-13 23:44:07

您可以创建如下方法:

Public Sub ExecuteSql( sqlString )
    Dim oConn
    Set oConn = Server.CreateObject("ADODB.Connection")
    oConn.Open connectionString
    oConn.Execute( CStr(sqlString) )
    oConn.Close
    Set oConn = Nothing
End Sub

注意:此例程假定 SQL 语句是由调用例程构建并正确转义的。此外,connectionString 是一个常量,您将其与数据库的连接字符串一起存储在某处。

调用示例:

Call ExecuteSql( "exec MyProc" )

You can create a method like this:

Public Sub ExecuteSql( sqlString )
    Dim oConn
    Set oConn = Server.CreateObject("ADODB.Connection")
    oConn.Open connectionString
    oConn.Execute( CStr(sqlString) )
    oConn.Close
    Set oConn = Nothing
End Sub

Note: This routine assumes that the SQL statement was built by the calling routine and properly escaped. In addition, connectionString is a constant that you store somewhere with the connection string to the db.

Example call:

Call ExecuteSql( "exec MyProc" )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文