Reputation: 1943
I want to know whether filestream in C# uses SQL Server authentication.
Is it possible to connect to the database using filestream in windows authentication by using userid and password?
Upvotes: 1
Views: 2607
Reputation: 980
Yes it is mandatory to use windows authentication filestream. Best thing to deal with it is impersonating it.
Declare the following methods inside the class
[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);
Then in the method:
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();
}
Upvotes: 1
Reputation: 62093
I want to know whether filestream in C# uses SQL Server authentication.
Depend what you think FileStream is. FileStream access via SQL uses whateve rthe SQL connectionuses. FileStream via windows - OBVIOUSLY - has to use windows authentication.
Is it possible to connect to the database using filestream in windows authentication by using userid and password?
Is it possible to connect to a windows share using username and pasword? YES. As long as thos ae are username and password ofa windows user.
Upvotes: 0