Yul*_*a V 9 c# sql-server connection-string database-connection
我有一个本地SQL Server数据库,启动并运行,我试图以一种看似非故障的方式连接到它:
new SqlConnection(@"Server=(localdb)\v12.0;Integrated Security=true;Database=MyDBName;");
Run Code Online (Sandbox Code Playgroud)
但是,这一行引发了一个异常:"'ServerVersion'引发了'System.InvalidOperationException'类型的异常?"?我该怎么办才能修好它?
我跑了
sqllocaldb create "v12.0"
Run Code Online (Sandbox Code Playgroud)
但它似乎没有任何区别.
小智 -1
创建一个方法:
private void connection()
{
con = new SqlConnection(ConfigurationManager.ConnectionStrings["conStrSheebu"].ConnectionString);
}
Run Code Online (Sandbox Code Playgroud)
在 web.config 中设置为:
<connectionStrings>
<add name="conStrSheebu" connectionString="Data Source=(local);Initial Catalog=Sheebu;User ID=sa;Password = AnsarI" providerName="System.Data.SqlClient" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
84943 次 |
最近记录: |