Using runas command to remotely logging into SQL Server

Kumar Vaibhav picture Kumar Vaibhav · Nov 9, 2012 · Viewed 24.7k times · Source

I am stuck at this point using the runas command. I am trying to log into a remote SQL Server instance using Windows Authentication on that server. I am using this command -

runas /netonly /user:Domain\Username 
      /server=someIP "C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe"

But when I do this, it opens up my Management Studio - the IP is of the remote server, Windows authentication is selected by default and I have my current system's domain and username.

I actually need a way to specify a connection string to log into a remote SQL Server and fire queries on it. It's cross domain.

One more question - do I need to have Management Studio on the machine I fire the query from?

Thanks.

EDIT

I am rephrasing for better understanding.

I have server A and server B(two separate computers). I need to fire a query from A on B. A does not have any sql server or management studio. B has both. I have to use windows authentication(something like myDomain\username) to log-in into sql server of B. I am using the runas command that I mentioned in the 'Target' in the properties of management studio on B. Is that wrong? I am logging in into A using a different username(but same domain) as that I have to login into B. How do I accomplish this task?

Thanks and sorry for the late edit.

Answer

TEEKAY picture TEEKAY · Nov 9, 2012

I use the following on a shortcut to run SSMS on an xp image that is NOT on the domain to connect to a server using domain credentials.

%windir%\System32\runas.exe /netonly /user:domain\username "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe -S SERVERNAME"