简体   繁体   English

在IIS APP_DATA文件夹中不在远程SQL Server本地创建的ASP.NET EF数据库

[英]ASP.NET EF database created local to remote SQL Server NOT in the IIS APP_DATA folder

I'm creating my first ASP.NET, EF code first web app. 我正在创建我的第一个ASP.NET,EF代码第一个Web应用程序。

The problem I have is in deploying and running it on a local IIS machine that is remote to the SQL Server Express ( SYSDEVSERVER ). 我遇到的问题是在远程SQL Server Express( SYSDEVSERVER )的本地IIS计算机上部署和运行它。

I'm unable to formulate a connection string that creates the EF DB in the App_Data folder of the web app. 我无法在网络应用程序的App_Data文件夹中制定用于创建EF DB的连接字符串。 Instead, the remote DB server, create a DB local to itself. 相反,在远程数据库服务器上,为其自身创建一个本地数据库。

The connection string that works (so far) is as follows: 目前有效的连接字符串如下:

<add name="MyWebApp" 
     connectionString="Data Source=SYSDEVSERVER\SQLEXPRESS; user id=USER;password=PASSWORD; Initial Catalog=MyDB; Trusted_Connection=no;" 
     providerName="System.Data.SqlClient" />

OK, so I'm not specifying an AttachDbFileName to say that the DB is in the App_Data folder of the web app - that's why the DB is created on the server. 好的,因此我没有指定AttachDbFileName来表示数据库位于Web应用程序的App_Data文件夹中-这就是在服务器上创建数据库的原因。

If I do specify AttachDbFilename like this: 如果我确实这样指定AttachDbFilename

AttachDbFilename=|DataDirectory|\MyDB.mdf

I get an error message 我收到一条错误消息

Invalid value for key 'attachdbfilename' 密钥“ attachdbfilename”的值无效

So far, I've been unable to resolve this, so for now I'll have to accept the DB residing local to the remote server, but I'm not too happy about it. 到目前为止,我一直无法解决此问题,因此,现在我必须接受驻留在远程服务器本地的数据库,但是对此我不太满意。

Does anyone know what connection string to use that allows the database to be created in the App_Data folder? 有谁知道使用哪个连接字符串允许在App_Data文件夹中创建数据库?

Thanks 谢谢

For local DB a conection string in this format should work 对于本地DB,应使用这种格式的连接字符串

<add name="MyWebApp" 
 connectionString="Data Source=(localdb)\v11.0;AttachDbFilename=|DataDirectory|\MyDB.mdf;Initial Catalog=MyDB;Integrated Security=True;"
 providerName="System.Data.SqlClient" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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