【问题标题】:Asp.net mvc 3 ctp create SQL Server Express data file in App_Data folderAsp.net mvc 3 ctp 在 App_Data 文件夹中创建 SQL Server Express 数据文件
【发布时间】:2011-05-25 01:08:21
【问题描述】:

我花了几天时间在App_data 文件夹中创建 SQL Server Express 数据库。 它总是在默认位置创建数据库。

我的 web.config 文件中有以下连接字符串。在默认位置创建的数据文件。

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

是否有可用的示例代码?

-sr

解决方案:

发布此消息后,我更改了我的连接,如下所示:

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

我在项目app_data文件夹中创建的数据文件。

现在我的问题是,我想在我的生产服务器中部署这段代码,将这个数据文件移动到生产服务器的最佳方法是什么?

我需要在生产服务器上安装 SQL Express 吗?

谢谢

-SR

【问题讨论】:

  • 您的问题到底是什么?可用于什么的示例代码?

标签: asp.net entity-framework entity-framework-4 sql-server-express


【解决方案1】:

现在我的问题是,我想部署 我的生产服务器中的这段代码, 移动这些数据的最佳方式是什么 文件到产品服务器?

最佳方式:在生产服务器上安装某种形式的 SQL Server(Express 或其他版本),然后将 MDF/LDF 文件复制到服务器并附加数据库;使用基于服务器的连接字符串来访问您的数据。

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

如果它在服务器上 - 不要使用 AttachDbFileName=..../User Instance=True kludge....

我需要安装 SQL Express 吗? 生产服务器?

您需要在服务器上一些版本的 SQL Server - 无论是 SQL Server Express 还是任何其他版本(标准版、Web 版、企业版)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-08
    • 1970-01-01
    • 2016-09-07
    • 2015-02-08
    • 1970-01-01
    • 2020-02-21
    • 1970-01-01
    相关资源
    最近更新 更多