SQL Connection String - Windows different user

Hi @vvaidya @aksh1yadav @akhi_s27 @Vikas.Jain @badita @beesheep,

I have logged into windows as user ‘abc123’ and then connected to sql server as different user ‘xyz456’,

in this case what would be the connection string ?

I’m unable to connect the usual way and doubt there should be something which I’m missing in my connection string for a different windows user, please share your thoughts guys.

Thanks!

If you are using UserID and Password in Connection string, you are connecting to that Database using SQL Authentication (user created in SQL DB), not your Windows credentials.

Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername;
Password=myPassword;

If you mention Integrated Security=SSPI;instead of User ID, Password, then you will be able to connect with your Windows Credentials provided you have enabled Windows Authentication (Or Mixed) in the DataBase.

Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
User ID=myDomain\myUsername;Password=myPassword;

More Info : SQL Server connection strings - ConnectionStrings.com

didn’t really worked. Tried all these options from google before posting here…

Thanks!

I was thinking SQL User, if this is a different Windows User, I doubt you can do that. Actually never tried.

yea, that’s what I’m after now. Tricky but that’s a requirement. pls see the screenshot below…

If I dont use the “Integrated Security=True”, then it really tries using the other user, but still it doesn’t goes through as shown below,

really appreciate if someone could share thier ideas/thoughts to resolve this…

Guys, any luck with this query ? Really appreciable. Thanks.!

Hi,

Anyone had any luck with this?

@loginerror @ovidiuponoran @lakshman
Hi guys, do you have a solution for this problem? (lines up)
I have the same doubt.

Try this:

@Joao_Victor_Neves_Monteir

I have logged in to machine using with one user and trying to connect the sql with different user with windows authentication. I have ran the below command -

runas /noprofile /netonly /user:domain\username ssms.exe

but still it is using/taking the same user Id by using which I have logged into machine. 

Another thing which I have tried is that - I have added a new windows user in windows credentials manager and tried to login into sql with that newly added user but still it is taking the user , by using which we have logged into machine. 

Please help

Old post but If anyone is looking for .NET Core solution, you will need to set SQL server connection string in appsettings.json

{
"ConnectionStrings": {
 "SQLServerAuth": "Data Source=Desktop-11\\SQL2017;Initial Catalog=SampleDB; User ID=sa;Password=pass1234"
 }
}

Source: SQL Server Connection String Examples