RE: Connect to database after windows impersonation.
- From: "Cowboy (Gregory A. Beamer) - MVP" <NoSpamMgbworld@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 6 Oct 2005 05:28:04 -0700
I would turn on Profiler with a filter to look at the particular database. In
particular, you want to see what credentials your application is trying to
use when it is failing. With that information, you should be better able to
determine what went wrong.
I noticed you are using a Console application. Is there any reason why you
cannot go to an application logon in SQL Server? If the app is only
distributed to authorized users (the best guarantee is Intranet only and
tightly controlled) or does not do anything that would cause damage if run at
the "wrong" time, an application role would make it a bit easier to connect
without using impersonation. Just a thought.
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
"SI" wrote:
> 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
.
- Prev by Date: Re: Working with different kinds of databases
- Next by Date: Re: SqlConnection
- Previous by thread: GetRows Equivalent
- Next by thread: Re: File Import Questions...
- Index(es):
Relevant Pages
|