我在使用 asp.net/C# 连接 sql server 2012 express 时遇到以下错误。我可以使用相同的用户和密码登录 sql server management studio,但是当我在连接字符串中使用它时,出现以下错误.
System.Data.OleDb.OleDbException:用户“user”登录失败
我的连接字符串是
<add name="DBConnectionString" connectionString="Server=localhost;Initial Catalog=sgweblog;Provider=SQLOLEDB;User Id=user;Password=password" providerName="System.Data.SqlClient"/>
请您参考如下方法:
您阅读了错误消息吗?登录失败。您的连接字符串几乎没问题,您可能指定了错误的数据库实例。尝试使用 localhost\SQLEXPRESS,因为 Express 版本安装在“SQLEXPRESS”命名实例下。
但再次请记住 - 正如错误消息所述,用户名和密码很可能不正确。
您是否尝试过使用可信连接并看看是否有效?
“数据源=localhost\SQLEXPRESS;Trusted_Connection=true;初始目录=YourDatabaseHere”
<add name="DBConnectionString" connectionString="Data Source=localhost\SQLEXPRESS;Trusted_Connection=true;Initial Catalog=YourDatabaseHere" />