0

I have problems defining the connection string in a windows service application. The SQL server and windows service are on different domains, and thats the problem. However, i know this is possible, because when using runas.exe in the terminal with this parameters there is no problem.

%windir%\system32\runas.exe /noprofile /netonly /user:DOMAIN1\%USERNAME% "ssms -nosplash -S SQLServerName -E"

So the problem should be in my connection string. How can i modify my connection string to access the server the same way? My connection string now looks lite this:

<connectionStrings>
<add name="MyEntities" connectionString="metadata=res://*/DataAccess.MyDatabase.csdl|res://*/DataAccess.MyDatabase.ssdl|res://*/DataAccess.MyDatabase.msl;
     provider=System.Data.SqlClient;provider connection string=&quot;data source=SQLServerName;
     initial catalog=MyDatabase;Trusted_Connection=yes;User Id=DOMAIN1\USERNAME;Password=*****;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>

UPDATE

Seams like it isnt possible to replicate the runas.exe command exactly. I tried to use impersonation like podiluska explained. But, this only works if the user can run on the current domain. In my case i cant, I want to send the windows credentials as parameters when connecting to the database, because that user cannot log on in the current domain. Can anybody confirm that this is impossible?

Zeezer
  • 1,503
  • 2
  • 18
  • 33

1 Answers1

0

You need to use impersonation - either in the IIS app pool, or by adding a line to the web.config

 <identity impersonate="true" userName="DOMAIN1\UserName" password="****" /> 

(and remove the user id / password entries from the connection string

podiluska
  • 50,950
  • 7
  • 98
  • 104
  • Tried adding that line () under tag in my app.config and then remove username/password from the connection string. But I still get this error: "Login failed: the login is from an untrusted domain and cannot be used with windows authentication" – Zeezer Jul 04 '12 at 08:29