Connecting To A Database Using Windows Authentication With Different Credentials using C#
<p>Perhaps someone can help me out here. I'm writing a program in C# to connect to a database on a remote server. The server in question uses Windows Authentication. I'm also not the admin of the server. </p>

<p>In any event to connect to server using SQL Server Management Studio I have to use a different credentials. So I use the runas.exe to connect.</p>

<p>Basically, Something along the lines of:</p>

<p>runas.exe /netonly /user:DIFFERENT_DOMAIN\SAME_USERNAME "C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe"</p>

<p>Using the runas.exe is the only way I can connect to the database, if I try running ssms without the runas, I will not connect at all.</p>

<p>So now my question. In the program I'm making in C#. How can I get my program to connect to the same database using different credentials without having to use runas.exe?</p>

<p>I've tried using:</p>

<pre><code>Sqlconnection sc = new Sqlconnection();
sc.ConnectionString = "Data Source= myServer;Initial Catalog= myDB;Integrated Security=true";
sc.Open();
</code></pre>

<p>But I just get "Login failed for user ''. User not associated with a trusted SQL Server Connection."</p>

<p>If I use the above code and Runas.exe with the correct credentials. It will work fine and connect. However I don't want to have to use it. </p>

<p>Anyone have any idea how to get the connection to work?</p>
