Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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!
Posted
Updated 6-Feb-12 16:19pm
v2

1 solution

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


VB
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
 
Share this answer
 
v2
Comments
Alan Tuscano 6-Feb-12 22:24pm    
Hi Chris,

Where will I put this code? I mean, where shall i write this code?
Chris Maunder 6-Feb-12 22:45pm    
I've updated the example to show you.
Alan Tuscano 7-Feb-12 20:43pm    
Hi Chris,
I have hard time understanding this(just a newbie in doing this).


create_RPTGR01_table
create_RPTXR01_table
create_RPTRR01_table
Above is a tables,
I created a script of this(in SSMS, right click on the table, SCRIPT TABLE, CREATE TO)

create_sp_GR01_query
create_sp_XR01_query
create_sp_RR01_query
Above is a Stored Procedures,
I created a script of this(in SSMS, right click on the SP, SCRIPT STORED PROCEDURE, CREATE TO)

I don't know to refer or call above mentioned,

In the CD Installation Package that I will do, above "Scripts" is included together with the VB Application and other Required Components.

When The User loads and run the CD, Set Up will commence, after Installing the Application and components, installation will proceed by
Reading the "Scripts" or "SP", Create it in the DB and Execute It.

How will I do the Read, Create, Execute in SSMS without the user knowing what is happening inside the installation.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900