c# - Connection string is not working while using (data source =.\SQLExpress)
问题描述
I'm using ASP.NET with C# and SQL Server
T have to use my .mdf
file inside the App_Data folder because I don't have access to the SQL database.
T have a problem with this connection string only if T use .\SQLExpress
<connectionStrings>
<add name="msscEduConnectionString"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MsscEdu.mdf;Integrated Security=True;"
providerName="System.Data.SqlClient"/>
</connectionStrings>
This connection string is not working and it shows error with attaching database
We have another site with connection string like this but different name and it works fine.
This is the connection string for the other site
<connectionStrings>
<add name="msdschoolkjConnectionString1" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\msdschoolkj.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
If I use the following connection string it works only on my computer but not the server
<connectionStrings>
<add name="msscEduConnectionString"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\MsscEdu.mdf;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
Can anyone assist?
解决方案
在你的 web.config 文件中试试这个
<connectionStrings>
<add name="ConnectionName"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|DatabaseName.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
推荐阅读
- c# - 为什么有时我们需要初始化结构而有时不需要?
- android - 是什么导致我的 AlertDialog 在 Firebase 回调方法中泄漏?
- php - 如何提高PHP邮件发送的效率?
- c++ - 用户模式驱动程序 (umdf) c++ http请求
- c# - 使用我的 NuGet 包编译项目的 .bond 文件
- javascript - Javascript重写
- c++ - 在菜单中显示加速键
- dataframe - 在 Julia 中使用人行横道翻译 Dataframe
- javascript - 是否可以从公共文件夹导入 vue 组件?
- algorithm - 在彼得森算法中启用标志之前设置转变量