When i am developing a product, i asked myself did i need to run the script after i installed the setup? is there any other way to run the script while i running the setup.
After a long search i found some results but i dont get any complete result for my search so i am post this hope it helps you...
Now i am going to run the script using VBScript.
Open the text editor like notepad
type the following code and save the file with extension .vbs
Dim cn
Set cn = CreateObject("ADODB.Connection")
cn.Open "Provider=SQLOLEDB;Data Source=.\SQLEXPRESS;Initial Catalog=master;Integrated Security=True;Integrated Security=SSPI;"
//This checks is their any database with this name.IF not it create the database.
cn.Execute "if not exists(select * from sys.databases where name = 'databasename') create database databasename"
cn.Execute "Use databasename"
//Then your regular scripts for creating table and stored procedure..
After saved this file add the file to you project.
select the setup and deployment project. Right click on the project from that menu select View--> Custom action
After that add custom action

It display the dialog box

- Double click the Application Folder.
- In that you already added the output of the project,in addition with add the Script.vbs file.
- Click ok and built the project and now you can run the script before run the setup file.
(Add the prerequisites as SQLexpress edition this will check whether it has sql server database before running the script otherwise you get the error message)

No comments:
Post a Comment