Deploying a database

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kitemad69@gmail.com

    Deploying a database

    How i can i deploy and attach a database from a C# project. I created
    the database in sql manager now i want to deploy it using a C# project
    is this possible
  • Alberto Poblacion

    #2
    Re: Deploying a database

    <kitemad69@gmai l.comwrote in message
    news:148d9583-a49a-4e6f-9c45-9392684ca194@u6 5g2000hsc.googl egroups.com...
    How i can i deploy and attach a database from a C# project. I created
    the database in sql manager now i want to deploy it using a C# project
    is this possible
    Assuming that Sql Server is already installed on the computer where you
    want to deploy the database, you have at least these options:

    1) You can attach the database. This would require dettaching it from the
    original server (or stopping the Sql Server) and copying the .mdf and .ldf
    files. You would then transfer those files to the computer where you want
    them deployed, and attach them to the local sql server by means of the
    adequate call to the sp_attach_db stored procedure which is documented in
    the Sql Server manuals. Of course, you can do this from C# by means of the
    ExecuteNonQuery method of a SqlCommand.

    2) If you are using Sql Server Express, and you want the database for local
    use in single-user mode, you can use the "user instance" mode of sql server.
    This doesn't require you to program anythig in your C# code (except copying
    the mdf file), you just have to edit your connection string so that it uses
    the necessary parameters for this mode of operation and contains the path to
    the copied mdf.

    3) You can use a backup. Extract the backup with Sql Manager, copy it to the
    deployment media, and restore it with a "Restore Database..." Sql query with
    adequate parameters. Of course, this query can be sent from C# with a
    SqlCommand and ExecuteNonQuery .

    In all three cases, you get the database on the deployment computer, but
    you still have to worry about security, because the database users contained
    in the database are mapped to sql logins in the original Sql Server, not in
    the deployment Sql Server. You can create users and grant permissions once
    again by sending the corresponding Sql calls with a SqlCommand. This is not
    needed if you are using a user instance, which always maps the current user
    to the dbo of the database.

    Comment

    Working...