RE: Connect to database after windows impersonation.



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
.



Relevant Pages

  • Re: IIS / SQL Server impersonation
    ... > I am attempting to implement impersonation from a windows application ... > to a SQL Server database via a remoting middleware application(hosted ... > I have configured the host virtual directory in IIS to require windows ... the database permits Windows Authentication. ...
    (microsoft.public.dotnet.security)
  • IIS / SQL Server impersonation
    ... I am attempting to implement impersonation from a windows application ... I have configured the host virtual directory in IIS to require windows ... the database permits Windows Authentication. ... When I try and open a connection to SQL Server: ...
    (microsoft.public.dotnet.security)
  • Re: Login failed for user NT AUTHORITYANONYMOUS LOGON
    ... Is the SQL server box in the same domain as the web server (or do they have ... went wrong with your impersonation. ... > I have a local webservice and I was to use to access a SQL server on their ... > of the domain user in the web.config. ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Permission required to execute a DTS package from ASP.NET applicatio?!!
    ... Yes,I've enabled impersonation in my application and that's why it is under ... > does SQL server is on the same server as your ASP.net application? ... >> I'm calling a DTS package from my asp.net application.Apparently because ... >> of the current security context and it is my Domian user name and I'm ...
    (microsoft.public.sqlserver.dts)
  • Re: Login failed for user MachineNameASPNET
    ... > Or is your SQL Server not on the same network? ... > Really impersonation is the best way, but I do remember a Visual Studio ... >> windows authentication to log into the site, ... >> programmatically override asp.net from providing the MachineName\ASPNET ...
    (microsoft.public.dotnet.framework.aspnet)