Click here to Skip to main content
15,916,189 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Don't call it a drone! Pin
CDP18026-Jun-17 9:49
CDP18026-Jun-17 9:49 
GeneralRe: Don't call it a drone! Pin
RossMW6-Jun-17 10:11
professionalRossMW6-Jun-17 10:11 
GeneralRe: Don't call it a drone! Pin
CDP18026-Jun-17 10:24
CDP18026-Jun-17 10:24 
GeneralWSO CCC OTD 2017-06-06 Rebooted Pin
OriginalGriff5-Jun-17 22:00
mveOriginalGriff5-Jun-17 22:00 
GeneralRe: WSO CCC OTD 2017-06-06 Rebooted Pin
Peter_in_27805-Jun-17 22:11
professionalPeter_in_27805-Jun-17 22:11 
GeneralRe: WSO CCC OTD 2017-06-06 Rebooted - we have de winner! Pin
OriginalGriff5-Jun-17 22:16
mveOriginalGriff5-Jun-17 22:16 
GeneralRe: WSO CCC OTD 2017-06-06 Rebooted - we have de winner! Pin
Peter_in_27805-Jun-17 22:28
professionalPeter_in_27805-Jun-17 22:28 
GeneralTo quote Grand Moff Tarkin... Pin
PIEBALDconsult5-Jun-17 13:53
mvePIEBALDconsult5-Jun-17 13:53 
Quote:
Holy crap! It works!


For a while now I've been meaning to update one of my WinForms applications at work.
It has a TabControl and each TabPage connects to a different database (SQL Server via Integrated Security; not SQL Authentication) to gather some information and present it.
BUT! I need to use three different users to connect to different systems and I don't like having to run an instance of the app for each user.
Each TabPage was already using its own Thread for database access, so I figured I should be able to use Impersonation.

And I got it working today! Jig | [Dance]

I use LogonUser (Win32 API P/Invoke) and create a System.Security.Principal.WindowsIdentity, then I pass the Identity to the appropriate TabPage's UserControl.
Thereafter, whenever the UserControl wants to access the database, it uses Impersonate.


(I'd still prefer something cleaner, but this seems to work as expected. Though I wouldn't be surprised if there's an Earth-shattering Kaboom in my future.)

modified 5-Jun-17 20:41pm.

PraiseRe: To quote Grand Moff Tarkin... Pin
Brisingr Aerowing5-Jun-17 15:44
professionalBrisingr Aerowing5-Jun-17 15:44 
GeneralRe: To quote Grand Moff Tarkin... Pin
Brisingr Aerowing5-Jun-17 16:52
professionalBrisingr Aerowing5-Jun-17 16:52 
GeneralRe: To quote Grand Moff Tarkin... Pin
raddevus5-Jun-17 17:03
mvaraddevus5-Jun-17 17:03 
GeneralRe: To quote Grand Moff Tarkin... Pin
Nelek5-Jun-17 19:53
protectorNelek5-Jun-17 19:53 
GeneralRe: To quote Grand Moff Tarkin... Pin
Sander Rossel5-Jun-17 21:30
professionalSander Rossel5-Jun-17 21:30 
GeneralRe: To quote Grand Moff Tarkin... Pin
Nelek6-Jun-17 0:02
protectorNelek6-Jun-17 0:02 
GeneralRe: To quote Grand Moff Tarkin... Pin
PIEBALDconsult6-Jun-17 5:29
mvePIEBALDconsult6-Jun-17 5:29 
GeneralRe: To quote Grand Moff Tarkin... Pin
raddevus6-Jun-17 8:19
mvaraddevus6-Jun-17 8:19 
GeneralRe: To quote Grand Moff Tarkin... Pin
F-ES Sitecore5-Jun-17 22:29
professionalF-ES Sitecore5-Jun-17 22:29 
GeneralRe: To quote Grand Moff Tarkin... Pin
PIEBALDconsult6-Jun-17 3:22
mvePIEBALDconsult6-Jun-17 3:22 
GeneralRe: To quote Grand Moff Tarkin... Pin
F-ES Sitecore6-Jun-17 3:34
professionalF-ES Sitecore6-Jun-17 3:34 
GeneralRe: To quote Grand Moff Tarkin... Pin
PIEBALDconsult6-Jun-17 5:20
mvePIEBALDconsult6-Jun-17 5:20 
GeneralRe: To quote Grand Moff Tarkin... Pin
dandy726-Jun-17 5:54
dandy726-Jun-17 5:54 
GeneralWe really in a perfect world shouldn't do it this way. Buttttttttttt.... Pin
rnbergren5-Jun-17 6:04
rnbergren5-Jun-17 6:04 
GeneralRe: We really in a perfect world shouldn't do it this way. Buttttttttttt.... Pin
Jeremy Falcon5-Jun-17 9:47
professionalJeremy Falcon5-Jun-17 9:47 
GeneralRe: We really in a perfect world shouldn't do it this way. Buttttttttttt.... Pin
CDP18025-Jun-17 10:44
CDP18025-Jun-17 10:44 
GeneralRe: We really in a perfect world shouldn't do it this way. Buttttttttttt.... Pin
Jeremy Falcon5-Jun-17 10:53
professionalJeremy Falcon5-Jun-17 10:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.