我一直在尝试让我的c#数据库应用程序在任何地方运行,但是在使用以下连接字符串时
<add name="DBCS"
connectionString="Data Source=(LocalDB)\v13;AttachDbFilename=|DataDirectory|\ServiceCardRecorderDatabase.mdf;Integrated Security=True;database=ServiceCardRecorderDatabase"
providerName="System.Data.SqlClient" />
当我尝试向表中插入数据时,我得到一个异常说法
System.Data.SqlClient.SqlException: 'A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. The specified LocalDB instance does not exist.
从Visual Studio抛出:
答案 0 :(得分:0)
尝试将web.config中实体框架部分的以下小节修改为
<parameters>
<parameter value="correctdbversion" />
</parameters>
其中correctdbversion可以是以下任一项,mssqllocaldb,v11.0,v12.0
答案 1 :(得分:0)
感谢所有人的努力,最后我发现使用下面的连接字符串解决了问题。
<add name="DBCS" connectionString="Data Source=(LocalDB)\mssqllocaldb;AttachDbFilename=|DataDirectory|\App_Data\ServiceCardRecorderDatabase.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
&#13;
我刚刚在| DataDirectory |之后添加了将mdf文件放在项目文件夹中的文件夹名称并按预期运行。