How can I create a new database on a (MSDE) SQL server from .NET?

Last post 07-05-2009 1:49 AM by Naom. 5 replies.

Sort Posts:

  • How can I create a new database on a (MSDE) SQL server from .NET?

    07-04-2009, 12:42 AM
    • Member
      41 point Member
    • sepid
    • Member since 04-06-2008, 8:32 AM
    • Posts 208

     Hi,

    I want to create a new database from .net . How should I do that?

    what is a connection string when there is no database ?

    Thanks

     

  • Re: How can I create a new database on a (MSDE) SQL server from .NET?

    07-04-2009, 2:54 AM
    Answer
    • Star
      12,473 point Star
    • malcolms
    • Member since 06-12-2008, 12:38 AM
    • Melbourne, Australia
    • Posts 2,050

    Use SMO to create a database, rather than crafting your own DDL.

    using Microsoft.SqlServer.Management.Common;
    using Microsoft.SqlServer.Management.Smo;

    Server server = new Server(@"locahost\sqlexpress");
    Database db = new Database(server, "YourDatabaseName");
    db.Create();

    You will also need to add references to the SMO assemblies to your project.

    Give that a try.

    Sincerely,
    Malcolm Sheridan

    Microsoft Certified Solution Developer
    Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as
    Answer" if a marked post does not actually answer your question.
  • Re: How can I create a new database on a (MSDE) SQL server from .NET?

    07-04-2009, 3:05 AM
    Answer

     You'll need to connect to the database server with the database as master database.

    Check out the code project article which explains this concept here.

    Regards

    Nilesh
    http://nileshgule.blogspot.com


    Please mark this as "ANSWER" if it helps you
  • Re: How can I create a new database on a (MSDE) SQL server from .NET?

    07-04-2009, 3:24 AM
    Answer

    http://support.microsoft.com/kb/305079

    http://www.codeproject.com/KB/aspnet/SQLDb_Using_Aspnet.aspx

  • Re: How can I create a new database on a (MSDE) SQL server from .NET?

    07-04-2009, 5:14 AM
    • Contributor
      5,110 point Contributor
    • RickNZ
    • Member since 01-01-2009, 3:43 AM
    • Nelson, New Zealand
    • Posts 856

    malcolms:

    Use SMO to create a database, rather than crafting your own DDL.

    using Microsoft.SqlServer.Management.Common;
    using Microsoft.SqlServer.Management.Smo;

    Server server = new Server(@"locahost\sqlexpress");
    Database db = new Database(server, "YourDatabaseName");
    db.Create();

    You will also need to add references to the SMO assemblies to your project.

    Give that a try.

    Gee, that response looks familiar somehow...

  • Re: How can I create a new database on a (MSDE) SQL server from .NET?

    07-05-2009, 1:49 AM
    • All-Star
      29,942 point All-Star
    • Naom
    • Member since 12-31-2007, 7:08 PM
    • Wisconsin
    • Posts 6,671

     Yes, I saw this reply somewhere recently L)

    Looking for a job opportunity.

    Beware of bugs in the above code; I have only proved it correct, not tried it.
    (Donald Knuth)

    Visit my blog

    PluralSight Learning Library
Page 1 of 1 (6 items)