Connecting Tech Pros Worldwide Forums | Help | Site Map

How would i run a create sql database script programmatically?

Sl1ver's Avatar
Member
 
Join Date: Mar 2009
Location: Cape Town, South Africa
Posts: 105
#1: Aug 12 '09
How would i run a create sql database script programmatically?
i want the the user to select the path of the script from a openfiledialog
and then run it. then the program saves the db path to a reg file(i know how to save to a reg file) just need help finding out where the sql db would lie to create a connection string and after all that boxes must appear for username and passwords

Any help on any part of this is much appreciated

Expert
 
Join Date: Jun 2008
Location: Pretoria, South Africa
Posts: 410
#2: Aug 12 '09

re: How would i run a create sql database script programmatically?


So all you want to do is execute a create DB script on a server?

You just need to create a connection to the server setting the initial catalog equal to 'master'.

Next read the .sql file into a SQL command and execute that command using the above mentioned connection.

A create DB script is is just like any other query. Any database specific settings can be set in the .sql file (which is really just a query). The DB will exist on the server which you specified with the Data Source property of the connection string.

Quote:

Originally Posted by Sl1ver View Post

after all that boxes must appear for username and passwords

What do you want to do with this?
Reply