简体   繁体   中英

How to connect to a SQL Server in a different domain in ASP.Net?

Here's the setup of the website:

ServerA: Application server with application pool Identity DomainA\\webUser.

ServerB: Database server with the SQL Server permissions set for DomainA\\webUser.

Both ServerA and ServerB are in the same domain, DomainA. This setup works fine. You can login to the website and do all that it allows you to do.

Now I'm sitting in an office and logged into my machine with DomainB\\meUser and also logged into VPN that allows me to access resources on DomainA (like I can RDP into DomainA\\ServerA or ServerB).

My problem is when I am trying to run my ASP.Net code it is unable to connect to the database as DomainA\\webUser. The exception I get:

Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.

I tried impersonating DomainA\\webUser in application and I get the error

Could not create Windows user token from the credentials specified in the config file. Error from the operating system 'Logon failure: unknown user name or bad password.

I can run the code and debug everything fine if I use a sql login (sql username and password).

So how do I setup the connection string so that I can debug the code? Thanks.

Open Visual Studio with the DomainA\\webUser credentials:

runas /netonly /user:DomainA\\webUser "C:\\Path\\devenv.exe"

You can check the full path for devenv.exe from the properties window of your current shortcut

You can create a .bat file with this command and open visual studio from there every time you need

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM