Click here to Skip to main content
12,633,764 members (31,925 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: SQL-server-2005 VB SQL-Server , +
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 6-Feb-12 17:17pm
Updated 6-Feb-12 17:19pm
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161208.2 | Last Updated 6 Feb 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100