在VB应用程序安装中执行SQL Server脚本. [英] Executing SQL Server Scripts at VB Application Installation.
问题描述
在计算机上安装VB应用程序时可以执行脚本吗?
我在本地服务器中创建了15个存储过程,我需要那个
15在另一台服务器上执行的存储过程.
我要做的测试是在SQL Server中打开脚本,并执行该脚本,使其成为该数据库的一部分.
是否可以将我的脚本作为安装包的一部分包含在我的VB Application SetUp中?
我正在使用VB 2008和SQL SERVER2005.
在此先感谢!
Hi,
Is it possible to execute Scripts, when installing VB Application on a computer?
I have 15 Stored Procedures that I created in my Local Server and I need that
15 Stored Procedures executed on another server.
What I do on testing is I open the scripts in SQL Server, and executed it so that it will be part of that database.
If its possible to include my Scripts in my VB Application SetUp , as part of the Installation package?
Im Using VB 2008 and SQL SERVER 2005.
Thanks in Advance!
推荐答案
是的.这是一个快速脚本.
假设您的数据库名为数据库",脚本文件位于FilePath中,而服务器为Server.
可以将这些代码放在.vbs文件(例如RunScript.vbs)中,并使用
执行
Yes. Here''s a quick script.
Assume your database is called "Database", the script file is in FilePath, and the server is Server.
This code can be placed inside a .vbs file (eg RunScript.vbs) and executed using
cscript RunScript.vbs
Dim command
command = """c:\Program Files\Microsoft SQL Server\100\Tools\Binn\SqlCmd.EXE"" " & "-S " & Server & " -d " & Database & " -i """ & Filepath & """ " &_
"-U " & Username & " -P " & Password & " -b"
' Execute the script
Dim process
set process = wshshell.Exec(command)
' Get any output of OSQL
Dim result
result = process.StdOut.ReadAll
' Get any error info
Dim error : error = process.StdErr.ReadAll
if error <> "" Then result = error
set process = nothing
' Output the result
if result <> "" Then WScript.StdOut.WriteLine result
这篇关于在VB应用程序安装中执行SQL Server脚本.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!