Com component

R

Ron Wallegie

Hi,

I am using an Com component from a extrernal software vendor. This component
accessess slq database. The problem is when we use this component in c# it
logges on to sql under the ASPNET account. For everything to work correctly
the username should be (domain\username). impersonation is enabled and works
correctly.
How can i work around this and startup the com component with user
credentials? please help...

Regards,

Ron
 
B

Brett Romero

Is this an ASP.NET app? If so, please post your
dataconfiguration.config file.

Brett
 
N

Nicholas Paldino [.NET/C# MVP]

Ron,

You can have the code run under another user by using the
WindowsImpersonationContext class (which you get an instance of when you
call the Impersonate method on the WindowsIdentity instance that represents
the identity that you want to run under).

Additionally, you can alter your web.config class to impersonate that
user, but generally, this is a bad idea.

If the number of calls are minimal, then I would create a wrapper for
the COM object and then make the calls to impersonate the user before the
call (and revert back when done).

You can also host this object in COM+, and have the configured identity
for the object be the user that you need to connect to the database (I'd
actually go this route, most likely).

Hope this helps.
 
W

Willy Denoyette [MVP]

Two questions;
Did you enable asp compatibility on the page (aspcompat = true)?
What kind of COM object is this, here I mean what are the apartment
requirements of the object you can check these using Oleview or directly in
the registry (look for "ThreadingModel"), if it's "apartment" you will have
to run the asp worker process under an account with privileges to
connect/access to SQL server. If it's "both" or "free" you can try to
impersonate the thread that creates the COM instance and calls into to
object. Note that it makes no sense to impersonate when the apartment
requirements are STA (apartment) or (worse) "Sinle".
Note also that when this COM object has STA (or single) requirements, it's
not designed to be hosted in asp.net and should better not be used in such
environment. A much better option is to drop it into a COM+ server type
application.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top