WPF数据库连接错误:The user is not associated with a trusted SQL Server connection.

时间:2021-11-20 13:30:14

我当初安装sql server的时候选的Window Authentication mode,没选SQL Server Windows Authentication。

后来做WPF时连接数据库时需要一个带密码的用户,新建用户步骤如下:

1.打开Microsoft sql server management studioexpress,以Window Authentication mode方式登录,选Sercurity,右击Logins,选New Login...

WPF数据库连接错误:The user is not associated with a trusted SQL Server connection.

2.然后如下图输入

WPF数据库连接错误:The user is not associated with a trusted SQL Server connection.WPF数据库连接错误:The user is not associated with a trusted SQL Server connection.WPF数据库连接错误:The user is not associated with a trusted SQL Server connection.

记得db_owner也选上

WPF数据库连接错误:The user is not associated with a trusted SQL Server connection.

3.右击已登录实例名,在左侧Select a page那里选Security,选SQL Server Windows AuthenticationWPF数据库连接错误:The user is not associated with a trusted SQL Server connection.

最后重启实例,右击实例名,选Restart.

新建实例后,打开VS,启动程序,在app.config文件中写连接语句

<connectionStrings>
    <add name="ConnStr"
             connectionString="Data Source=(local);Initial Catalog=FamilyFinancialSys;Persist Security Info=True;User ID=FamilyFinancial;Password=f123456"
            providerName="System.Data.SqlClient" />
  </connectionStrings>

点F5运行程序,如果还报错The user is not associated with a trusted SQL Server connection.

打开SQL Server Configuration Manager,如果你装过多个sql server,写Data Source=(local);会不知道选哪个连接,所以你得写明白到底连接的是哪个。

从Start中选Run(运行)输入services.msc,查看你正在运行的sql server是那个

连接语句改为

<connectionStrings>
    <add name="ConnStr"
             connectionString="Data Source=(写你自己的Server name);Initial Catalog=FamilyFinancialSys;Persist Security Info=True;User ID=FamilyFinancial;Password=f123456
       providerName="System.Data.SqlClient" />
  </connectionStrings>