Results 1 to 10 of 10
  1. #1
    Join Date
    Oct 2009
    Posts
    16

    Unanswered: Connect Using Different Windows account to SQl Server DB

    Hi,

    Is it possible to programmatically connect to SQL Server Database in Windows Authentication mode by using windows account username and password which is different from the account logged into windows .

    If yes can anyone please share code snippet for doing so.

  2. #2
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Version of SQL? What are you connecting from?
    Testimonial:
    pootle flump
    ur codings are working excelent.

  3. #3
    Join Date
    Oct 2009
    Posts
    16
    I am trying to connect to SQL Server 2008 from a Windows console application which is on .NET 3.5.

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    In that case I don't really know. That is really a .NET question.
    In T-SQL you can use the EXECUTE AS command to change your user\ login context, but I don't know how to actually connect to SQL Server using different Windows Accounts without logging on and off.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Right click the app and choose "Run as..." ??
    George
    Home | Blog

  6. #6
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Check MSDN for the "Fabricam" examples. They show how to write an application that uses different Windows Authenticated connections to SQL Server.

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  7. #7
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    There are tons of examples, if you search for "impersonate". For a console app you even have more options, including RUNAS, let alone doing impoersonation inside the code. Here's a start for you:
    Windows Impersonation using C# - CodeProject
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

  8. #8
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Oh crap yes - I've written impersonation code in C#. Totally forgot about that....
    Testimonial:
    pootle flump
    ur codings are working excelent.

  9. #9
    Join Date
    Aug 2010
    Posts
    1

    Connect Using Different Windows account to SQl Server DB

    The only way to achieve what you want is opening several instances of SSMS by right clicking on shortcut and using the 'Run-as' feature.

  10. #10
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Psst, Henry, have you read the other replies to this thread? That's clearly not the only way
    George
    Home | Blog

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •