Results 1 to 3 of 3

Thread: [RESOLVED] Create db sql server from script with vb.net

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2012
    Posts
    12

    Resolved [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.

  2. #2
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    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.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2012
    Posts
    12

    Re: Create db sql server from script with vb.net

    Thanks Janner, i do it and works. thank you very much for your help.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width