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="data source=SQLServerName;
initial catalog=MyDatabase;Trusted_Connection=yes;User Id=DOMAIN1\USERNAME;Password=*****;multipleactiveresultsets=True;App=EntityFramework"" 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?