我正在尝试使用以下代码在 C# 中打开我的本地数据库:
SqlConnection c = new SqlConnection("Server = (LocalDB)\\v11.0 ;Integrated Security=True;Database =Informati;");
c.Open();
但是当他试图打开它时我收到一个错误:
Cannot open database "Informati" requested by the login. The login failed.
Login failed for user 'AURELIAN121\Aurelian'.
我试过使用
连接new SqlConnection("Server = (LocalDB)\v11.0 ;User id=AURELIAN121\Aurelian;Integrated Security=True;Database =Informati;");
但错误仍然存在。
最佳答案
您的连接字符串不正确: 对于本地数据库,你也可以使用点,比如
SqlConnection c = new SqlConnection("Data Source=.;
Integrated Security=True;Initial Catalog=Informati;");
从错误来看,您的本地用户没有访问 Sql server 的权限。你必须先添加创建登录:http://www.reliasoft.com/support/rs40024.htm
关于c# - sql本地数据库连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26944365/