Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I authenticate to a SQL Server database on a domain from a virtual machine off the domain?

I am supporting a .NET 4.0 (Visual Studio 2010) web application that authenticates to a SQL Server 2008 database which resides on my work intranet. The application authenticates to the database using windows authentication. Thats all fine and dandy if Im developing on my host, but I am developing on a virtual machine that is not on the work domain. Thus when the project build and runs, it throws a SqlClient.SqlException

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

Short of developing on my host and abandoning the VM, what can I do to avoid this error and successfully authenticate to the database so I can build/run the web app? I am willing to store my credentials somewhere locally, though preferably not somewhere that would be under TFS source control (like the web.config) because I couldnt keep the file checked out since there are other developers on the project.

I have tried running Visual Studio as a different user (as the user on my work domain) but I get a "unknown user name or bad password" error.

Note, adding the Virtual Machine to the domain (or connecting to it via VPN) are not options. The VM must remain off the domain. Also note, the virtual machine is running on the computer that is on the domain, and the VM uses a shared connection. So it CAN access the intranet but it can't perform windows authentication to SQL Server.

like image 809
n00b Avatar asked Nov 01 '12 21:11

n00b


1 Answers

You can run Visual Studio (or SQL Server Management Studio) as the user on the domain. The trick is, you have to use the “/netonly” option of the “runas” Windows tool, so that you can run as a domain user on a non-domain machine.

Namely, in a command prompt you run this command (filling in your own criteria):

runas /netonly /user:<Domain>\<User_Name> "<Your_Program.exe>"

Alternatively, you can create a shortcut on your desktop, and set this command as the shortcut target. Upon running the shortcut/command, you enter your credentials when prompted and visual studio (or whatever program you like) will run as the domain user.

like image 114
n00b Avatar answered Oct 12 '22 21:10

n00b