简体   繁体   English

使用Windows模拟连接到SQL Server

[英]Connect to SQL Server using Windows impersonation

I wrote a windows service in C# and I have to use windows authentication to SQL server. 我用C#编写了Windows服务,并且必须对SQL Server使用Windows身份验证。 So I am using Trusted Connection in the SQL connection string. 因此,我在SQL连接字符串中使用了Trusted Connection。

Here's the set up: Windows service has WCF hosted with in it. 设置如下:Windows服务中托管了WCF。 Windows service uses local service account which is admin on that application server... Because the WCF has to register the uri. Windows服务使用该应用程序服务器上的admin本地服务帐户...因为WCF必须注册uri。 So I impersonate another account which will use Windows auth to SQL server... I am not given a SQL account.. So the problem is when I try to auth after impersonation... It's trying to use the account under which the service is running even though I check windows identity and it's correct and is the impersonated account.Why is it using the service account? 因此,我模拟了另一个将使用Windows身份验证对SQL Server的帐户...我没有获得SQL帐户。.问题是当我在模拟后尝试进行身份验证...它正在尝试使用该服务所使用的帐户即使我检查Windows身份并且它是正确的并且仍是模拟帐户,仍可以运行。为什么要使用服务帐户?

Another question is, one of the methods of the WCF service returns a list of all exceptions... This list works when it is empty or if I put a new exception in it but if the Windows service threw the exception and that exception goes into the list and I try to retrieve it it says no end point. 另一个问题是,WCF服务的方法之一返回所有异常的列表...当该列表为空或是否在其中添加新异常但Windows服务引发了异常并且该异常进入了该列表时,此列表将起作用该列表,我尝试检索它,说没有终点。 Any ideas? 有任何想法吗? It isn't timing out or anything bc I increased the times. 不是超时,也不是我增加了时间。 I have other methods that just return strings and they work fine. 我还有其他只返回字符串的方法,它们可以正常工作。

Ok I figured this out after more debugging. 好的,经过更多调试后,我发现了这一点。 The impersonation was working fine but my decrypted password wasn't correct. 模仿工作正常,但是我解密的密码不正确。 So fixed that. 如此固定。

The question about the list of exceptions not being retrieved... Apparently .Net couldn't serialized the exception class. 关于未检索到的异常列表的问题...显然.Net无法序列化异常类。 So I wrote a custome class that returns exception info and it works great. 因此,我编写了一个custome类,该类返回异常信息,并且效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM