简体   繁体   English

当我将数据库属性转换为不复制时,底层提供程序无法打开

[英]Underlying provider failed to open when I convert database property to do not copy

This is the connection string and when I change the property of the database file ( database1.mdf ) to "do not copy", it causes an error. 这是连接字符串,当我将数据库文件( database1.mdf )的属性更改为“请勿复制”时,将导致错误。

<connectionStrings>
    <add name="ClassLibrary1.Properties.Settings.Database1ConnectionString" 
         connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True" 
         providerName="System.Data.SqlClient" />
</connectionStrings>

That's probably because of AttachDbFilename=|DataDirectory|\\Database1.mdf that you can't not copy the database to the DataDirectory. 这可能是因为AttachDbFilename=|DataDirectory|\\Database1.mdf ,您无法将数据库复制到DataDirectory。

The connection string tries to find and attach the database from the given address and it can't find it. 连接字符串尝试从给定地址查找并附加数据库,但找不到。 you can attach the db first and then use this connection strings: 您可以先附加数据库,然后使用以下连接字符串:

<add provider connection string=&quot;data source=.;
    initial catalog=Database1;
    integrated security=True;/>

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

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