0

I spent few days to create SQL Server Express database in App_data folder. It always creating database in default location.

I have following connection string in my web.config file. data file created in default location.

  <connectionStrings>
    <add name="PersonDBContext"
          connectionString="Data Source=.\SQLEXPRESS;AttachDbFileName=Customers.mdf;Integrated Security=True;User Instance=True;Persist Security Info=True;"
         providerName="System.Data.SqlClient" />       
  </connectionStrings>

Is there a working sample code available for this?

-sr

Solution:

After posting this message I changed my connection like this:

<connectionStrings> 
   <add name="PersonDBContext"
        connectionString="data source=.\SQLEXPRESS;Initial Catalog=CustomerInfoDB;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\Customers.mdf;User Instance=true"
        providerName="System.Data.SqlClient" />
  </connectionStrings>

my data file creating in project app_data folder.

Now my question is, I want to deploy this code in my production server, what is the best way to move this data file to prod server?

Do I need to install SQL Express on production server?

Thanks

-SR

1
  • What exactly is your question here? A sample code available for what?
    – Ry-
    May 25, 2011 at 1:11

1 Answer 1

2

Now my question is, I want to deploy this code in my production server, what is the best way to move this data file to prod server?

Best way: install some form of SQL Server (Express or another edition) on your production server, and copy your MDF/LDF files to the server and attach the database; use a server-based connection string for accessing your data.

<connectionStrings>
   <add name="PersonDBContext"
        connectionString="Server=YourServerName;Database=Customers;Integrated Security=True;"
        providerName="System.Data.SqlClient" />       
</connectionStrings>

If it's on a server - don't use the AttachDbFileName=..../User Instance=True kludge....

Do I need to install SQL Express on production server?

You need some edition of SQL Server on the server - doesn't matter whether it's SQL Server Express, or any of the other editions (Standard, Web, Enterprise).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.