G
Guest
Hi,
I've developed a small C# windows console application for testing purposes.
What it does is, it impersonates a user on the same domain, and then
populates a dataTable by executing a stored procedure located on a remote
machine. All machines are in the same AD domain, and the impersonated user
has admin rights on the SQL server box and the SQL Server (2000 SP3a) itself.
Below is a code snippet:
-----------------------------
static void Main(string[] args)
{
WindowsImpersonationContext context = null;
try
{
string user = "user1";
string domain = "dom";
string pwd = "password";
//do the impersonation by calling am method in the class Impersonation I
wrote
context = new Impersonation().CreateIdentity(user, domain,
pwd).Impersonate();
// open a connection to the database an do the rest....
}
finally
{
if (context != null)
context.Undo();
}
}
----------------------------
The problem I'm getting is that when this is ran, I keep getting the error:
"SQL Server does not exist or access denied."
If I take out the impersonation call, it works fine.
With the impersonation call, it gives that error, in both cases where I
specify a SQL Login in the connectioon string, or specify trusted connection
in the connection string.
It also works okay if I run this on the machine that has the SQL server on
it. It is only when I run this from a different machine, and have the
windows impersonation, does this throw that error.
Any ideas anyone?
Thanks in advance
SI
I've developed a small C# windows console application for testing purposes.
What it does is, it impersonates a user on the same domain, and then
populates a dataTable by executing a stored procedure located on a remote
machine. All machines are in the same AD domain, and the impersonated user
has admin rights on the SQL server box and the SQL Server (2000 SP3a) itself.
Below is a code snippet:
-----------------------------
static void Main(string[] args)
{
WindowsImpersonationContext context = null;
try
{
string user = "user1";
string domain = "dom";
string pwd = "password";
//do the impersonation by calling am method in the class Impersonation I
wrote
context = new Impersonation().CreateIdentity(user, domain,
pwd).Impersonate();
// open a connection to the database an do the rest....
}
finally
{
if (context != null)
context.Undo();
}
}
----------------------------
The problem I'm getting is that when this is ran, I keep getting the error:
"SQL Server does not exist or access denied."
If I take out the impersonation call, it works fine.
With the impersonation call, it gives that error, in both cases where I
specify a SQL Login in the connectioon string, or specify trusted connection
in the connection string.
It also works okay if I run this on the machine that has the SQL server on
it. It is only when I run this from a different machine, and have the
windows impersonation, does this throw that error.
Any ideas anyone?
Thanks in advance
SI