我有一个简单的控制台应用程序,连接到SQL Server数据库。然而,在运行时它会抛出以下错误。有什么线索吗?
Unhandled Exception: System.Data.SqlClient.SqlException: Cannot open database "Database" requested by the login. The login failed.
Login failed for user 'MYDOMAIN\MYUSERID'.
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, BooleanignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
我使用的是SQL Server 2005 Express Edition。 然而,我可以通过Database Explorer从Visual Web Developer连接到SQL Server。 下面是我使用的代码:
using System;
using System.Data;
using System.Data.SqlClient;
public class Test
{
public Test()
{
}
static void Main()
{
Console.WriteLine("hello");
string connectionString = "Data Source=localhost\\SQLEXPRESS;Database=Database;Integrated Security=true";
SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
Console.WriteLine("done");
}
}