我想知道C#中的文件流是否使用SQL Server身份验证。
是否可以通过使用用户名和密码在 Windows 身份验证中使用文件流连接到数据库?
是的,必须使用 Windows 身份验证文件流。
对付它最好的办法就是模仿它。
在类中声明以下方法
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwlogonType, int dwlogonProvider, out SafeTokenHandle phtoken);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern bool CloseHandle(IntPtr handle);
然后在方法中:
public void method()
{
WindowsImpersonationContext context = null;
SafeTokenHandle safeTokenHandle;
bool returnValue = LogonUser(connString[0], connString[1], connString[2], Convert.ToInt32(connString[3]), Convert.ToInt32(connString[4]), out safeTokenHandle);
WindowsIdentity windowsIdentity = new WindowsIdentity(safeTokenHandle.DangerousGetHandle());
context = windowsIdentity.Impersonate();
//Make some operations
context.undo();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)