The user is not associated with a trusted SQL Server Connection

本文介绍了如何解决SQL Server中常见的连接错误“The user is not associated with a trusted SQL Server connection”。主要原因是实例仅设置为Windows身份验证而非混合模式。文章提供了通过SQL Server Management Studio或注册表编辑器更改设置的方法。

 

 
  
The user is not associated with a trusted SQL Server Connection
2009-05-06 00:57

Source:http://decipherinfosys.wordpress.com/2008/11/14/the-user-is-not-associated-with-a-trusted-sql-server-connection/

support.microsoft.com/kb/889615

If you have worked with SQL Server for some time, you must have faced this error at some time or the other:

 

This error can come due to a couple of reasons. The most common reason is that the instance that you are trying to connect to has been set up as one with only Windows Only Authentication rather than Windows and SQL Server Authentication. You can check that easily by either by SSMS (SQL Server Management Studio) or in the registry settings as well (in case you do not have the client tools loaded up on the instance where you are getting this error and you inherited this set up from someone).

In SSMS, after you log in using your Windows Authentication, right click on the server and choose “Properties” and then go to the Security page and change the “Server Authentication” to be “SQL Server and Windows Authentication mode” as shown in the image below:

 

Once that is done, you will need to re-start the MSSQLServer service in order for the changes to take place.

The place where it gets stored in the registry is:

 

HKLM/Software/Microsoft/Microsoft SQL Server/MSSQL.2005/MSSQLServer

LoginMode - if it is 1, then it is Windows mode and if it is 2, it is mixed mode (Windows and SQL Server).

Now, other times you can also get this error with a blank user name i.e:

Login failed for user . The user is not associated with a trusted SQL Server connection

You can get that error in a couple of scenarios:

1) If the server name has a space after it’s name, example: in the connection string you have specified: servername ,1433 i.e. that extra space after the servername (the instance name).
2) Not being able to resolve the Windows account that is trying to connect to the SQL Server instance. Here are some scenarios that we have seen at client sites when this happens:

a) When using Windows authentication and the machine from where the connection is being made, instead of using a domain account, a local account on that machine is being used for making the connection to the SQL Server instance. This is obviously because the domain controller and SQL Server cannot recognize the local account on other machines.

b) In the case of web applications, the account that runs IIS does not have access to SQL Server. You have to impersonate a domain user account in ASP.Net for this. This KB article covers this in detail.

c) Another common reason is when communication is being made across domains which do not have a trust relationship set up between them.

d) We have also seen this in scenarios where because of heavy network load, communication between SQL Server and the Domain Controller is hindered.

sec_23

sec_22

sec_21
`UnboundLocalError: cannot access local variable 'XXX' where it is not associated with a value` 是 Python 中一种常见的运行时错误,它表明在函数内部试图访问一个局部变量,但在访问之前没有为其分配任何值。这类错误通常与变量作用域和初始化顺序有关。 当一个变量在函数内部被赋值时,Python 默认将其视为局部变量。如果在赋值之前尝试读取该变量的值,则会触发此错误。例如: ```python def example_function(): print(x) # 尝试打印x的值 x = 5 # x在此处才被赋值 example_function() ``` 上面的代码会导致 `UnboundLocalError`,因为 `x` 在函数体内的某个地方被赋值了,因此它被视为局部变量,但在 `print(x)` 语句执行时还没有被赋予任何值[^3]。 解决这个问题的方法之一是在使用变量之前确保它已经被初始化。可以给变量一个默认值或者确保所有可能的执行路径都能为变量提供一个值。比如: ```python def calculate_score(some_condition): score = 0 # 初始化score变量 if some_condition: score = 10 return score # 假设some_condition为False print(calculate_score(False)) # 输出0 ``` 在这个例子中,无论 `some_condition` 的真假如何,`score` 变量都有一个初始值 `0`,这样即使条件不满足也不会出现未初始化的错误。 如果你确实需要在函数内部修改全局变量,那么你需要使用 `global` 关键字来声明这个变量是全局的,而不是创建一个新的局部变量。例如: ```python score = None # 全局变量 def set_score(value): global score score = value set_score(10) print(score) # 输出10 ``` 通过这种方式,可以在函数内部安全地访问和修改全局变量。 此外,对于更复杂的情况,可能需要检查逻辑流程是否正确处理了所有的分支情况,以确保每个分支都正确地初始化了相关的变量。理解作用域规则以及何时何地定义和使用变量是避免此类错误的关键。
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值