Sql Server express 2005 deployment

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?UHVuaXQgS2F1cg==?=

    Sql Server express 2005 deployment

    Hi,

    I am developing a windows application in VS.NET 2005. The application is
    database driven and I need to deploy it on a client's pc. How should I go
    about developing such an application. I remember I did something once long
    back .. like including .mdf files into my project in the solution explorer of
    VS 2005 and then used Click Once deployment tool ... to make sure that the
    database and tables were created when the client installed my application.
    Now I seem to have forgotten the procedure and cannot find any other
    resource. Iwould be really grateful if someone could guide me through it.

    Do I have to create a .mdf file or does SQL Sever 2005 automatically create
    one when I create a database. If yes where does it save the file. And then
    what are the next steps after having an existing .mdf file...

    Thank you.

  • Mr. Arnold

    #2
    Re: Sql Server express 2005 deployment

    >
    Do I have to create a .mdf file or does SQL Sever 2005 automatically
    create
    one when I create a database. If yes where does it save the file. And then
    what are the next steps after having an existing .mdf file...
    >
    The MDF and LDF files are going to be located at Program Files/Microsoft Sql
    Server/MSSQL.1/MSSQL/DATA.

    As far as the rest of the stuff about deployment of a .Net solution using MS
    Sql Server Express, I ran across articles out there on Google showing the
    how to.

    Comment

    • =?Utf-8?B?UHVuaXQgS2F1cg==?=

      #3
      Re: Sql Server express 2005 deployment


      Ya I tried to do that... going to the folder and selecting the mdf file....
      it said "An error occurred"... i will try it gain tomorrow.

      Thank you

      "Mr. Arnold" wrote:
      >

      Do I have to create a .mdf file or does SQL Sever 2005 automatically
      create
      one when I create a database. If yes where does it save the file. And then
      what are the next steps after having an existing .mdf file...
      >
      The MDF and LDF files are going to be located at Program Files/Microsoft Sql
      Server/MSSQL.1/MSSQL/DATA.
      >
      As far as the rest of the stuff about deployment of a .Net solution using MS
      Sql Server Express, I ran across articles out there on Google showing the
      how to.
      >
      >

      Comment

      • =?Utf-8?B?QWRyaWFuIFZvaWN1?=

        #4
        Re: Sql Server express 2005 deployment


        When you want to deploy your sql database with a project, you need to make a
        backup of your database. When you make the back up, create the mdf and the
        ldf files. Take these copies and deploy them with your application. You
        cannot copy the mdf or ldf files while SQL is running. You need to stop the
        SQL Server process before you can do that.

        Adrian.
        [Please mark my answer if it was helpful to you]




        "Punit Kaur" wrote:
        >
        Ya I tried to do that... going to the folder and selecting the mdf file....
        it said "An error occurred"... i will try it gain tomorrow.
        >
        Thank you
        >
        "Mr. Arnold" wrote:
        >
        >
        Do I have to create a .mdf file or does SQL Sever 2005 automatically
        create
        one when I create a database. If yes where does it save the file. And then
        what are the next steps after having an existing .mdf file...
        >
        The MDF and LDF files are going to be located at Program Files/Microsoft Sql
        Server/MSSQL.1/MSSQL/DATA.

        As far as the rest of the stuff about deployment of a .Net solution using MS
        Sql Server Express, I ran across articles out there on Google showing the
        how to.

        Comment

        • =?Utf-8?B?UHVuaXQgS2F1cg==?=

          #5
          Re: Sql Server express 2005 deployment


          Thanks for the suggestion. I created a local database using Add new item in
          VS .NET and created a table. Now I am having trouble with the Connection
          String.

          When I used the following connection string which has the relative path to
          the file:

          public const string DB_CONN_STRING = "Data
          Source=.\\SQLEX PRESS;AttachDbF ilename=|DataDi rectory|\\Monit orApp.mdf;Integ rated Security=True;U ser Instance=True";

          and try to insert into the table.. it does not do anything. It also does not
          throw any exception when I execute the following stmt:

          myCommand.Execu teNonQuery();

          which is enclosed within a try block

          When I hard coded the connection string to point to the .mdf file by giving
          the exact path..

          Data
          Source=.\SQLEXP RESS;AttachDbFi lename=C:\curre nt_working\RM\M onitorApp\Monit orApp\MonitorAp p.mdf;Integrate d Security=True;U ser Instance=True

          I was able to succefully insert in to the table.

          So It means there is something wrong in the relative path that uses
          |DataDirectory| .

          Can someone please point out if you see anything wrong....

          The path of my VS.NET project's solution is C:\current_work ing\RM\MonitorA pp\


          I think I need to make sure that the relative path works fine... so as to be
          able to correctly deploy sql server express.

          Please suggest.

          Thanks a lot.





          C:\current_work ing\RM\MonitorA pp\MonitorApp\


          "Mr. Arnold" wrote:
          >

          Do I have to create a .mdf file or does SQL Sever 2005 automatically
          create
          one when I create a database. If yes where does it save the file. And then
          what are the next steps after having an existing .mdf file...
          >
          The MDF and LDF files are going to be located at Program Files/Microsoft Sql
          Server/MSSQL.1/MSSQL/DATA.
          >
          As far as the rest of the stuff about deployment of a .Net solution using MS
          Sql Server Express, I ran across articles out there on Google showing the
          how to.
          >
          >

          Comment

          • =?Utf-8?B?QWRyaWFuIFZvaWN1?=

            #6
            Re: Sql Server express 2005 deployment


            You don't have to create a local database in this case. In the connection
            string you should only specify the name of the server where the database is
            and not the path to the mdf. So connect to the actual database when you
            develop your code. When you are done, make a backup of your sql database,
            take the mdf + ldf files that you created with the backup and attach them to
            your installation package.

            Adrian.
            ----
            [Please mark my answer if it was helpful to you]



            "Punit Kaur" wrote:
            >
            Thanks for the suggestion. I created a local database using Add new item in
            VS .NET and created a table. Now I am having trouble with the Connection
            String.
            >
            When I used the following connection string which has the relative path to
            the file:
            >
            public const string DB_CONN_STRING = "Data
            Source=.\\SQLEX PRESS;AttachDbF ilename=|DataDi rectory|\\Monit orApp.mdf;Integ rated Security=True;U ser Instance=True";
            >
            and try to insert into the table.. it does not do anything. It also does not
            throw any exception when I execute the following stmt:
            >
            myCommand.Execu teNonQuery();
            >
            which is enclosed within a try block
            >
            When I hard coded the connection string to point to the .mdf file by giving
            the exact path..
            >
            Data
            Source=.\SQLEXP RESS;AttachDbFi lename=C:\curre nt_working\RM\M onitorApp\Monit orApp\MonitorAp p.mdf;Integrate d Security=True;U ser Instance=True
            >
            I was able to succefully insert in to the table.
            >
            So It means there is something wrong in the relative path that uses
            |DataDirectory| .
            >
            Can someone please point out if you see anything wrong....
            >
            The path of my VS.NET project's solution is C:\current_work ing\RM\MonitorA pp\
            >
            >
            I think I need to make sure that the relative path works fine... so as to be
            able to correctly deploy sql server express.
            >
            Please suggest.
            >
            Thanks a lot.
            >
            >
            >
            >
            >
            C:\current_work ing\RM\MonitorA pp\MonitorApp\
            >
            >
            "Mr. Arnold" wrote:
            >
            >
            Do I have to create a .mdf file or does SQL Sever 2005 automatically
            create
            one when I create a database. If yes where does it save the file. And then
            what are the next steps after having an existing .mdf file...
            >
            The MDF and LDF files are going to be located at Program Files/Microsoft Sql
            Server/MSSQL.1/MSSQL/DATA.

            As far as the rest of the stuff about deployment of a .Net solution using MS
            Sql Server Express, I ran across articles out there on Google showing the
            how to.

            Comment

            • =?Utf-8?B?UHVuaXQgS2F1cg==?=

              #7
              Re: Sql Server express 2005 deployment

              I am unable to understand one thing....

              Like you suggested, If I have to connect to the specific server on my local
              machine.. the connection string would be specific to my machine. So when I
              attach the mdf and ldf files.. when the customer is installing it on his
              machine, how will the application connect to that database... since it will
              need to use a different connection string. Can I provide the DB connection
              string in the installation package? I have never done this before so I have
              no idea!!

              Thanks




              "Adrian Voicu" wrote:
              >
              You don't have to create a local database in this case. In the connection
              string you should only specify the name of the server where the database is
              and not the path to the mdf. So connect to the actual database when you
              develop your code. When you are done, make a backup of your sql database,
              take the mdf + ldf files that you created with the backup and attach them to
              your installation package.
              >
              Adrian.
              ----
              [Please mark my answer if it was helpful to you]
              >
              >
              >
              "Punit Kaur" wrote:
              >

              Thanks for the suggestion. I created a local database using Add new item in
              VS .NET and created a table. Now I am having trouble with the Connection
              String.

              When I used the following connection string which has the relative path to
              the file:

              public const string DB_CONN_STRING = "Data
              Source=.\\SQLEX PRESS;AttachDbF ilename=|DataDi rectory|\\Monit orApp.mdf;Integ rated Security=True;U ser Instance=True";

              and try to insert into the table.. it does not do anything. It also does not
              throw any exception when I execute the following stmt:

              myCommand.Execu teNonQuery();

              which is enclosed within a try block

              When I hard coded the connection string to point to the .mdf file by giving
              the exact path..

              Data
              Source=.\SQLEXP RESS;AttachDbFi lename=C:\curre nt_working\RM\M onitorApp\Monit orApp\MonitorAp p.mdf;Integrate d Security=True;U ser Instance=True

              I was able to succefully insert in to the table.

              So It means there is something wrong in the relative path that uses
              |DataDirectory| .

              Can someone please point out if you see anything wrong....

              The path of my VS.NET project's solution is C:\current_work ing\RM\MonitorA pp\


              I think I need to make sure that the relative path works fine... so as to be
              able to correctly deploy sql server express.

              Please suggest.

              Thanks a lot.





              C:\current_work ing\RM\MonitorA pp\MonitorApp\


              "Mr. Arnold" wrote:
              >

              Do I have to create a .mdf file or does SQL Sever 2005 automatically
              create
              one when I create a database. If yes where does it save the file. And then
              what are the next steps after having an existing .mdf file...

              >
              The MDF and LDF files are going to be located at Program Files/Microsoft Sql
              Server/MSSQL.1/MSSQL/DATA.
              >
              As far as the rest of the stuff about deployment of a .Net solution using MS
              Sql Server Express, I ran across articles out there on Google showing the
              how to.
              >
              >

              Comment

              • =?Utf-8?B?UHVuaXQgS2F1cg==?=

                #8
                Re: Sql Server express 2005 deployment


                Alright , I have connected to the actual database and I also made a backup.
                The backup generates a .bak file. The mdf and ldf files were already created
                when I created the database. Back up created only one .bak file. What do I do
                now?

                Also can you please tell me about any free installer package where I could
                include these files. Or does one come with the VS 2005? If yes, where can I
                find it. Any tutorial on how to proceed with this?

                Thanks a lot.




                "Adrian Voicu" wrote:
                >
                You don't have to create a local database in this case. In the connection
                string you should only specify the name of the server where the database is
                and not the path to the mdf. So connect to the actual database when you
                develop your code. When you are done, make a backup of your sql database,
                take the mdf + ldf files that you created with the backup and attach them to
                your installation package.
                >
                Adrian.
                ----
                [Please mark my answer if it was helpful to you]
                >
                >
                >
                "Punit Kaur" wrote:
                >

                Thanks for the suggestion. I created a local database using Add new item in
                VS .NET and created a table. Now I am having trouble with the Connection
                String.

                When I used the following connection string which has the relative path to
                the file:

                public const string DB_CONN_STRING = "Data
                Source=.\\SQLEX PRESS;AttachDbF ilename=|DataDi rectory|\\Monit orApp.mdf;Integ rated Security=True;U ser Instance=True";

                and try to insert into the table.. it does not do anything. It also does not
                throw any exception when I execute the following stmt:

                myCommand.Execu teNonQuery();

                which is enclosed within a try block

                When I hard coded the connection string to point to the .mdf file by giving
                the exact path..

                Data
                Source=.\SQLEXP RESS;AttachDbFi lename=C:\curre nt_working\RM\M onitorApp\Monit orApp\MonitorAp p.mdf;Integrate d Security=True;U ser Instance=True

                I was able to succefully insert in to the table.

                So It means there is something wrong in the relative path that uses
                |DataDirectory| .

                Can someone please point out if you see anything wrong....

                The path of my VS.NET project's solution is C:\current_work ing\RM\MonitorA pp\


                I think I need to make sure that the relative path works fine... so as to be
                able to correctly deploy sql server express.

                Please suggest.

                Thanks a lot.





                C:\current_work ing\RM\MonitorA pp\MonitorApp\


                "Mr. Arnold" wrote:
                >

                Do I have to create a .mdf file or does SQL Sever 2005 automatically
                create
                one when I create a database. If yes where does it save the file. And then
                what are the next steps after having an existing .mdf file...

                >
                The MDF and LDF files are going to be located at Program Files/Microsoft Sql
                Server/MSSQL.1/MSSQL/DATA.
                >
                As far as the rest of the stuff about deployment of a .Net solution using MS
                Sql Server Express, I ran across articles out there on Google showing the
                how to.
                >
                >

                Comment

                • =?Utf-8?B?QWRyaWFuIFZvaWN1?=

                  #9
                  Re: Sql Server express 2005 deployment


                  Ok, that's good. You can now attach the database bak file to your
                  installation package. To make an installation package use the build in setup
                  & deployment install wizard that steps through all the settings. When
                  prompted to select what additional files to bundle up with the package,
                  select your SQL database backup file.

                  If size is an issue, you can also create a script file of your database. Use
                  SQL Server Management Studio to log in and right click on the database you
                  want to deploy. Select "Script Database As"->"Create To"->"File" and then
                  save the file. This file contains the code to recreate your database and
                  takes less space than the previous method. Add the file to your install
                  wizard by using the same steps as above.

                  Ok, now that you have an installation package you can now install your
                  program + database file to the host computer. Obviously the client will need
                  SQL Server 2005 installed on their end for this to work. With the database
                  bak or script file on the client computer you need to log into SQL Server
                  Management Studio on the client and either use the bak file to restore the
                  database from the backup or run the script file to produce a new database.
                  Both options are manual. When done, update you application's config file to
                  point to the new database server - you only need to change the "Data Source"
                  string in the connection string. That's it.

                  To make this automatic, I think you need to make a custom dll that launches
                  during installation and runs the script to create the database. This might
                  run into security problems though and you would also need to know the name of
                  the database server to install to and at the end change the application
                  config file.

                  Adrian.
                  --
                  [Please mark my answer if it was helpful to you]




                  "Punit Kaur" wrote:
                  >
                  Alright , I have connected to the actual database and I also made a backup.
                  The backup generates a .bak file. The mdf and ldf files were already created
                  when I created the database. Back up created only one .bak file. What do I do
                  now?
                  >
                  Also can you please tell me about any free installer package where I could
                  include these files. Or does one come with the VS 2005? If yes, where can I
                  find it. Any tutorial on how to proceed with this?
                  >
                  Thanks a lot.
                  >
                  >
                  >
                  >
                  "Adrian Voicu" wrote:
                  >

                  You don't have to create a local database in this case. In the connection
                  string you should only specify the name of the server where the database is
                  and not the path to the mdf. So connect to the actual database when you
                  develop your code. When you are done, make a backup of your sql database,
                  take the mdf + ldf files that you created with the backup and attach them to
                  your installation package.

                  Adrian.
                  ----
                  [Please mark my answer if it was helpful to you]



                  "Punit Kaur" wrote:
                  >
                  Thanks for the suggestion. I created a local database using Add new item in
                  VS .NET and created a table. Now I am having trouble with the Connection
                  String.
                  >
                  When I used the following connection string which has the relative path to
                  the file:
                  >
                  public const string DB_CONN_STRING = "Data
                  Source=.\\SQLEX PRESS;AttachDbF ilename=|DataDi rectory|\\Monit orApp.mdf;Integ rated Security=True;U ser Instance=True";
                  >
                  and try to insert into the table.. it does not do anything. It also does not
                  throw any exception when I execute the following stmt:
                  >
                  myCommand.Execu teNonQuery();
                  >
                  which is enclosed within a try block
                  >
                  When I hard coded the connection string to point to the .mdf file by giving
                  the exact path..
                  >
                  Data
                  Source=.\SQLEXP RESS;AttachDbFi lename=C:\curre nt_working\RM\M onitorApp\Monit orApp\MonitorAp p.mdf;Integrate d Security=True;U ser Instance=True
                  >
                  I was able to succefully insert in to the table.
                  >
                  So It means there is something wrong in the relative path that uses
                  |DataDirectory| .
                  >
                  Can someone please point out if you see anything wrong....
                  >
                  The path of my VS.NET project's solution is C:\current_work ing\RM\MonitorA pp\
                  >
                  >
                  I think I need to make sure that the relative path works fine... so as to be
                  able to correctly deploy sql server express.
                  >
                  Please suggest.
                  >
                  Thanks a lot.
                  >
                  >
                  >
                  >
                  >
                  C:\current_work ing\RM\MonitorA pp\MonitorApp\
                  >
                  >
                  "Mr. Arnold" wrote:
                  >

                  >
                  Do I have to create a .mdf file or does SQL Sever 2005 automatically
                  create
                  one when I create a database. If yes where does it save the file. And then
                  what are the next steps after having an existing .mdf file...
                  >

                  The MDF and LDF files are going to be located at Program Files/Microsoft Sql
                  Server/MSSQL.1/MSSQL/DATA.

                  As far as the rest of the stuff about deployment of a .Net solution using MS
                  Sql Server Express, I ran across articles out there on Google showing the
                  how to.

                  Comment

                  • =?Utf-8?B?UHVuaXQgS2F1cg==?=

                    #10
                    Re: Sql Server express 2005 deployment


                    Hi,

                    Thank you for the detailed steps. From your answer I infer that the client
                    will need to manually do things which is not my intention. I remember doing
                    it in an easier way where I did not even need to do anything manually except
                    for installing the .msi package that had the database .mdf files along with
                    all the other components like .net 2 framework besides the actual
                    application. Also since the connection string was relative and I am using
                    "localhost" instead of my machinename, I had no problems installing and
                    running the application. I remember I had used the "Publish" wizard in VS.NET
                    2005.

                    However, since now I am having connection string problems when I am using
                    |DataDirectory| in the connection string to access .mdf file... I thought
                    that the solution you were giving would not require the client to do anything
                    once I attached .mdf files.

                    Is there any way besides the custom dLL solution where we can do it without
                    having to restore the database or do anything manually on the clients
                    computer?

                    Thanks



                    "Adrian Voicu" wrote:
                    >
                    Ok, that's good. You can now attach the database bak file to your
                    installation package. To make an installation package use the build in setup
                    & deployment install wizard that steps through all the settings. When
                    prompted to select what additional files to bundle up with the package,
                    select your SQL database backup file.
                    >
                    If size is an issue, you can also create a script file of your database. Use
                    SQL Server Management Studio to log in and right click on the database you
                    want to deploy. Select "Script Database As"->"Create To"->"File" and then
                    save the file. This file contains the code to recreate your database and
                    takes less space than the previous method. Add the file to your install
                    wizard by using the same steps as above.
                    >
                    Ok, now that you have an installation package you can now install your
                    program + database file to the host computer. Obviously the client will need
                    SQL Server 2005 installed on their end for this to work. With the database
                    bak or script file on the client computer you need to log into SQL Server
                    Management Studio on the client and either use the bak file to restore the
                    database from the backup or run the script file to produce a new database.
                    Both options are manual. When done, update you application's config file to
                    point to the new database server - you only need to change the "Data Source"
                    string in the connection string. That's it.
                    >
                    To make this automatic, I think you need to make a custom dll that launches
                    during installation and runs the script to create the database. This might
                    run into security problems though and you would also need to know the name of
                    the database server to install to and at the end change the application
                    config file.
                    >
                    Adrian.
                    --
                    [Please mark my answer if it was helpful to you]
                    >
                    >
                    >
                    >
                    "Punit Kaur" wrote:
                    >

                    Alright , I have connected to the actual database and I also made a backup.
                    The backup generates a .bak file. The mdf and ldf files were already created
                    when I created the database. Back up created only one .bak file. What do I do
                    now?

                    Also can you please tell me about any free installer package where I could
                    include these files. Or does one come with the VS 2005? If yes, where can I
                    find it. Any tutorial on how to proceed with this?

                    Thanks a lot.




                    "Adrian Voicu" wrote:
                    >
                    You don't have to create a local database in this case. In the connection
                    string you should only specify the name of the server where the database is
                    and not the path to the mdf. So connect to the actual database when you
                    develop your code. When you are done, make a backup of your sql database,
                    take the mdf + ldf files that you created with the backup and attach them to
                    your installation package.
                    >
                    Adrian.
                    ----
                    [Please mark my answer if it was helpful to you]
                    >
                    >
                    >
                    "Punit Kaur" wrote:
                    >

                    Thanks for the suggestion. I created a local database using Add new item in
                    VS .NET and created a table. Now I am having trouble with the Connection
                    String.

                    When I used the following connection string which has the relative path to
                    the file:

                    public const string DB_CONN_STRING = "Data
                    Source=.\\SQLEX PRESS;AttachDbF ilename=|DataDi rectory|\\Monit orApp.mdf;Integ rated Security=True;U ser Instance=True";

                    and try to insert into the table.. it does not do anything. It also does not
                    throw any exception when I execute the following stmt:

                    myCommand.Execu teNonQuery();

                    which is enclosed within a try block

                    When I hard coded the connection string to point to the .mdf file by giving
                    the exact path..

                    Data
                    Source=.\SQLEXP RESS;AttachDbFi lename=C:\curre nt_working\RM\M onitorApp\Monit orApp\MonitorAp p.mdf;Integrate d Security=True;U ser Instance=True

                    I was able to succefully insert in to the table.

                    So It means there is something wrong in the relative path that uses
                    |DataDirectory| .

                    Can someone please point out if you see anything wrong....

                    The path of my VS.NET project's solution is C:\current_work ing\RM\MonitorA pp\


                    I think I need to make sure that the relative path works fine... so as to be
                    able to correctly deploy sql server express.

                    Please suggest.

                    Thanks a lot.





                    C:\current_work ing\RM\MonitorA pp\MonitorApp\


                    "Mr. Arnold" wrote:

                    >

                    Do I have to create a .mdf file or does SQL Sever 2005 automatically
                    create
                    one when I create a database. If yes where does it save the file. And then
                    what are the next steps after having an existing .mdf file...

                    >
                    The MDF and LDF files are going to be located at Program Files/Microsoft Sql
                    Server/MSSQL.1/MSSQL/DATA.
                    >
                    As far as the rest of the stuff about deployment of a .Net solution using MS
                    Sql Server Express, I ran across articles out there on Google showing the
                    how to.
                    >
                    >

                    Comment

                    • ainsleyp@gmail.com

                      #11
                      Re: Sql Server express 2005 deployment

                      Use a connection string that looks like this:

                      Data Source=.\SQLEXP RESS;AttachDbFi lename=|DataDir ectory|
                      MyDatabase.mdf; User Instance=True;I ntegrated Security=True

                      This will attach using a user instance. That means you don't have to
                      do anything manual like attaching the database in SQL Server
                      Management Studio. You just include Sql Server 2005 Express in the
                      installation (it's even in the Prerequisites list in your Setup
                      project so you just have to check a box), and just include the
                      database files with the setup.

                      It makes it difficult to remotely connect into the database, but if
                      you don't need to do that then stick with user instances. They're
                      quite convenient.

                      Paul

                      On Jul 18, 1:24 pm, Punit Kaur <PunitK...@disc ussions.microso ft.com>
                      wrote:
                      Hi,
                      >
                      Thank you for the detailed steps. From your answer I infer that the client
                      will need to manually do things which is not my intention. I remember doing
                      it in an easier way where I did not even need to do anything manually except
                      for installing the .msi package that had the database .mdf files along with
                      all the other components like .net 2 framework besides the actual
                      application. Also since the connection string was relative and I am using
                      "localhost" instead of my machinename, I had no problems installing and
                      running the application. I remember I had used the "Publish" wizard in VS.NET2005.
                      >
                      However, since now I am having connection string problems when I am using
                      |DataDirectory| in the connection string to access .mdf file... I thought
                      that the solution you were giving would not require the client to do anything
                      once I attached .mdf files.
                      >
                      Is there any way besides the custom dLL solution where we can do it without
                      having to restore the database or do anything manually on the clients
                      computer?
                      >
                      Thanks
                      >

                      Comment

                      Working...