Impersonation and delegation with OrmLite?

This question goes above the context of OrmLite, but I’m trying to get it working with OrmLite at the moment. I need to connect to Sql Server from a non-domain machine with the server only allowing trusted connections via a domain login (a la Trusted_Connection=True). Is this possible? I know it can be done via the *nix library FreeTDS somehow (a Mac SQL client is connecting fine that uses FreeTDS), so I’m hoping there’s some possibility of doing it in C#. I’ve tried a few things using WindowsImpersonationContext but not getting very far. These kinds of authentication things go past my expertise.

Anybody ever done this?

I’ve never done this, do you know how to do this with raw ADO.NET?

Not yet. Just seeing if anyone else had any trails I could go down.

In that case I’d ask the larger audience on StackOverflow on how to do this with ADO.NET first, if that’s possible we could apply the same technique in OrmLite.

That’s what I’m thinking. Thanks.

I’ve posted on SO. In the meantime, I just thought of something…won’t this be an issue when people start running .NET Core apps/sites on a Linux instance where the site needs to connect to a SQL Server via trusted auth?

Using SQL Server WindowsAuth is usually an issue for non Windows OS’s. IMO it’s an ugly source of issues so I avoid it for all of my apps and just use a connection string with user/pass.

Very much agreed. But surely they’ll have to support windows auth somehow in Core. Otherwise there’ll be a lot of DBAs with their undies in a wad.

I actually got a working example going, but it wouldn’t be x-plat. It relies on doing a P/Invoke to mpr.dll and calling WNetAddConnection2.

1 Like