简体   繁体   中英

Asp.net mvc 3 ctp create SQL Server Express data file in App_Data folder

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

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM