Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2006
    Posts
    11

    Question Unanswered: sql connection string

    I want to let C# code to create a database, so

    * I set up an asp.net server on local machine.
    (plus I create "web" under the "wwwroot", I want all my code & database
    there)

    * Set up sql connection by string:
    "Server=theNameOfMyComputer;
    Database=theNameOfDatabase;
    Trusted_Connection=True;"

    Q:
    * sever == name of local computer?
    * If I specify the database here, can I
    create a new database?

    * some c# code & sql statement to create a new database.

    figo2476

  2. #2
    Join Date
    Dec 2002
    Posts
    1,245
    Some things that CAN be done probably ought NOT be done...

    That said:

    1. Connect to db "master"
    2. User must have dbcreator privilege
    3. Check out CREATE DATABASE in BOL
    4. After database is created, either discconect and re-connect (substituting the name of the database that was created for master) or issue a USE [database name] statement.

    Again, some things that CAN be done might not necessarily be the best WAY to accomplish a particular task.

    Regards,

    hmscott
    Have you hugged your backup today?

  3. #3
    Join Date
    Apr 2006
    Posts
    11
    Could you give me a complete example how a connection string looks like?
    I am not really sure of this.

    figo2476

    Quote Originally Posted by hmscott
    Some things that CAN be done probably ought NOT be done...

    That said:

    1. Connect to db "master"
    2. User must have dbcreator privilege
    3. Check out CREATE DATABASE in BOL
    4. After database is created, either discconect and re-connect (substituting the name of the database that was created for master) or issue a USE [database name] statement.

    Again, some things that CAN be done might not necessarily be the best WAY to accomplish a particular task.

    Regards,

    hmscott

  4. #4
    Join Date
    Mar 2003
    Location
    Reading, UK
    Posts
    70
    try this
    Connection_string = "Driver={SQL Server};Server=<local-server>;Database=master; Uid=sa;Pwd=<pwd>;"

    session("ConnectionString")=Connection_string

    execute the create database stmt

    session("ConnectionString")=""

    Connection_string = "Driver={SQL Server};Server=<local-server>;Database=<new db>; Uid=sa;Pwd=<pwd>;"

    session("ConnectionString")=Connection_string

    regards,
    Pavan.

Posting Permissions

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