Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In my network I have a SERVER with 5 clients. In one of my client, I have Visual Studio 2010 and in my SERVER I have OS 2003 and SQL SERVER 2005. I have created a database in my SERVER . In the particular client where my VB 2010 is installed I have made a project by adding datasource from the database created in the SERVER. Now I have build my project with setup and deployment wizard. My simple application runs fine from any of my client machine in my network. It saves data perfectly in my database created in the SERVER. BUT when I tried to run my application in a different network in another SERVER, I cant. It runs in different SERVER only if I restore my database from my own SERVER to that SERVER manualy in Enterprise manager.

Now how can I create/attach/restore my database in a different SERVER while installing my application in that SERVER. What I have to do in VB and SQL.Kindly use VB code. Kindly also tell me how the setup.exe while installing in a different SERVER promt for the SERVER name, USER, Password at the begining of execution of my application so that the database may be attached to the SQL SERVER automatically.
Posted
Updated 23-Jun-12 10:54am
v2

1 solution

Ok - let's break this down ...

1. You need the SQL 'definition' of your DB, logins, indices et al

This one is easy :) In SQL Management Studio, right click your DB, choose Generate Scripts, follow the wizard, and you should have the script required to create your DB from scratch

2. You need to ask the customer for
- SQL server details
- SQL admin login credentials, or integrated login
- name of the db to drop/create (don't ever assume the customer is happy with your choice of DB name)
- path to create it to, or use the SQL default

3. You need to execute the scripts generated in #1 on the server in #2

4. Your application needs to understand some items from #2
- server
- dbname

Items 2 & 3 can be done in a number of ways, here, we use Custom Scripts, Custom Tables and Custom UIs inside the MSI/setup.exe file, this may be beyond the scope you wish to take on, but there's an example A Setup and Deployment project that passes parameters to the configuration file[^] that talks about doing bits of that

You could install the sql scripts generated from #1 into a directory, then have a VBscript custom action run them, using information from the UI

Or alternatively, you could have a VB exe run the first time your app is run - and that should be easy to identify, because your app won't have any information it needs from #4

That should get you going ;)

Another thing to consider is having a schemaNumber table in your DB, then you can create update scripts by simply running a windiff over v1 #1 script and v2 #1 scripts
 
Share this answer
 
Comments
dibyendudhar 26-Jun-12 10:06am    
Thankyou Barneyman for your useful post and the link. You have almost understood my problem. The link is very useful to me but still I cant solve it. Can you pl help me more.
1. Where and how I will paste the script (required to create my DB) in Visual Basic( by creating a button in the form)
2. Your alternative idea "Or alternatively, you could have a VB exe run the first time your app is run - and that should be easy to identify, because your app won't have any information it needs from #4" is very good. How can I do this.
Some more help may be required. Waiting for your kind help.
barneyman 26-Jun-12 10:18am    
1. just have your VB app or MSI vb-script crawl thru a directory, loading scripts (perhaps order them alphabetically) and running them - I have not used VB with SQL, but I can't believe it's difficult

2. Your primary app will be getting #4 information from the registry, or config file, if it's not there, you spawn your VB app that does the script running

Your fundamental issue is generating the SQL scripts to create your DB, how and when you run them, is up to you
dibyendudhar 3-Jul-12 1:21am    
Thankyou Barneyman.I have almost done the project. But as I am a beginner to Visual Basic, if you could help me more by giving your kind advice on subject, I may complete my project. Thanks onece again.
barneyman 3-Jul-12 1:26am    
LOL - I haven't touched VB in nearly 20 years ... what are you after?

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