I am running integration tests with C #, NUnit, and SQL Server 2008 r2 dev edition. Configuring my device involves creating a new database and loading test data, so for this I need dbo privileges.
However, I want to run tests with less privileges. I have another AD account with which I can authenticate, and I can run some T-SQL using impersonation, as described here: http://support.microsoft.com/?scid=306158 , as follows
public static bool ExecuteFileAs(string fileName, string connectionString,
string user, string domain, string password)
{
using(new Impersonator(user, domain, password))
{
using(var connection = new SqlConnection(connectionString))
{
connection.Open();
return SqlFileExecuter.RunSql(connection, fileName);
}
}
}
When I hit the breakpoint inside this code snippet and started Profiler, I see that another connection is open with the username I passed to it, so the impersonation really works. Unfortunately, I can not run all the tests issued at the end of the lamp setup, and ending it when the mount is broken. At the end of the setup, I do the following:
impersonator = new Impersonator("username", "DOMAIN", "pwd");
As soon as the first unit test starts, I get this error by listing one of the DLLs used in this test: System.IO.FileLoadException: Could not load file or assembly '...' or one of its dependencies. Access is denied.
I gave the other account full access to the directory with all my binaries, which did not help.
Any suggestions are welcome.
Edit: XP is still running on my workstation.