Where is the SQL Server MDF database once deployed in production?

답변됨 Where is the SQL Server MDF database once deployed in production?

  • 2012년 7월 26일 목요일 오전 8:33
     
      코드 있음

    Hello everyone,

    I've developed a website project in VS2010 that includes the ASPNETDB.MDF database. In the project package/publish settings I select the option Exclude files from App_Data folder and when importing the package into IIS7.5 the database is located in the Users\AppData\... folder. So far so good, however I have the following questions:

    Q1 - Importing the project into IIS7.5 works and the database is created successfully but my connectionString syntax in the web.config seems not correct since it causes an error on pages that have SQL DataSource objects. The error is: Invalid value for key 'attachdbfilename'. The connection string is:

    Data Source=localhost\SQLExpress;AttachDBFilename=|DataDirectory|\XYZWebDBTST20.mdf;Initial Catalog=XYWebDBTST20;User ID=XYZWebDBUser;Integrated Security=SSPI;Persist Security Info=False

    Q2 - When I finally upload the package to the web where will the database be located?

    Q3 - Do I really need to know or will the connection string |DataDirectory| keyword automatically point to the correct location?

    Many thanks in advance for any help.

    Have a wonderful day...

    Regards

    Michael

    • 이동됨 Bob BeaucheminMVP 2012년 7월 26일 목요일 오후 4:52 This is really a deployment choice, maybe for ASP.NET forums. Moving to closest SQL Server forum (I have no access to move to ASP.NET forum) (From:.NET Framework inside SQL Server)
    •  

모든 응답

  • 2012년 7월 26일 목요일 오전 9:17
     
      코드 있음

    Hello everyone,

    I've developed a website project in VS2010 that includes the ASPNETDB.MDF database. In the project package/publish settings I select the option Exclude files from App_Data folder and when importing the package into IIS7.5 the database is located in the Users\AppData\... folder. So far so good, however I have the following questions:

    Q1 - Importing the project into IIS7.5 works and the database is created successfully but my connectionString syntax in the web.config seems not correct since it causes an error on pages that have SQL DataSource objects. The error is: Invalid value for key 'attachdbfilename'. The connection string is:

    Data Source=localhost\SQLExpress;AttachDBFilename=|DataDirectory|\XYZWebDBTST20.mdf;Initial Catalog=XYWebDBTST20;User ID=XYZWebDBUser;Integrated Security=SSPI;Persist Security Info=False

    Q2 - When I finally upload the package to the web where will the database be located?

    Q3 - Do I really need to know or will the connection string |DataDirectory| keyword automatically point to the correct location?

    Many thanks in advance for any help.

    Have a wonderful day...

    Regards

    Michael

    PS

    After some research I found the solution to questions one:

    Data Source=localhost\SQLExpress;Database=XYZWebDBTST21.mdf;Initial Catalog=XYZWebDBTST21;User ID=XYZWebDBUser;Integrated Security=SSPI;Persist Security Info=False

    This works on web pages with a asp:SQLDataSource objects, however on another page where I retrieve the connection string with C# it doesn't work. It doesn't through an error it just hangs and doesn't do anything.

    My C# code is straight from MSDN and looks like:

        // Get SQL Connection String
        static private string dsGetConnectionString()
        {
          // Get the application path needed to obtain
          // the application configuration file.
          string appName = Environment.GetCommandLineArgs()[0];
    
          string appexePath = System.IO.Path.Combine(Environment.CurrentDirectory, appName);
    
          // Get the application configuration file.
          System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(appexePath);
    
          // Get the connectionStrings section.
          ConnectionStringsSection csSection = config.ConnectionStrings;
    
          // Select the section.
          ConnectionStringSettings cs = csSection.ConnectionStrings[0];
    
          //  Return connection string.
          return cs.ConnectionString;
        }
    


  • 2012년 7월 29일 일요일 오전 2:08
    중재자
     
     답변됨

    Hi Michael,

    You could post the case in ASP.NET Forum. You would receive better and quicker support.

    Thanks,
    Maggie


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. This can be beneficial to other community members reading the thread.

    • 답변으로 표시됨 Michael754 2012년 7월 29일 일요일 오전 8:22
    • 답변으로 표시 취소됨 Michael754 2012년 8월 2일 목요일 오전 10:03
    • 답변으로 표시됨 Michael754 2012년 8월 8일 수요일 오전 3:14
    •