[RESOLVED] Create db sql server from script with vb.net
Hello. Sorry for my bad english but i need help. I developed a maintenance software but i need to work with separated bases. For example, one db 'Electric_M', another 'Mecanic_M' another 'computer_M'. I created a single db (contains multiple tables, relations, etc...) and i need to create more bases with the same structure using a vb.net form.
I need to program an option to "Create new db". This new db should have the same tables, relations, etc... but without records. I read that i can do it with the script of the base. Can someone explaindme how do this?
I would greatly appreciate your help.
Bye.
Re: Create db sql server from script with vb.net
If you can export your database schema as an SQL file, you should get a text file filled with the SQL commands required to re-create the database.
You save it in your programming project as a resource.
Then, if you want to create a new database from scratch, you use ADO.NET to create a connection to the database server, load that text file into your program as a string, and execute it as a command.
If you make any changes or alterations to your database schema, you just re-export it and replace the file in your programming project with the new one.
This is the technique I use. I first have my program try to connect to the database server stored in it's configuration file.
If it connects, then I have it do a few commands to see if the database I want exists on the server.
If not (Try/Catch) then I prompt the user if they would like to install a new, blank database on the server. If yes, I have it execute a batch of SQL commands from an external file to create database, create table a, create table b... etc.
Re: Create db sql server from script with vb.net
Thanks Janner, i do it and works. thank you very much for your help.