跪求解决啊 数据库连接的问题
我的数据库可以打开,也可以查看里面的数据库。但是我用VS2010写的程序,却无法打开数据库,总是说登录失败。
string strcon = @"Server=(local)\\SQLExpress;Initial Catalog=MBOOK;Integrated security =true";
//@"Data Source=.;Initial Catalog=XJGL;Integrated security =SSPI ";china-18b9ac675\SQL2008User ID=sa;Password=123456
//@"Date Source =china-18b9ac675\SQL2008;Initial Catalog=XJGL;Integrated Security=SSPI";
这些常用的语句我试过了。现在用的是
string strcon = @"Server=(local)\\SQLExpress;Initial Catalog=MBOOK;Integrated security =true";
出现的错误是
“/”应用程序中的服务器错误。
--------------------------------------------
实例失败。
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.InvalidOperationException: 实例失败。
源错误:
行 32: cmd.Parameters.Add("@account", SqlDbType.Char, 20).Value = TextBox3.Text.Trim();
行 33: cmd.Parameters.Add("@password", SqlDbType.Char, 20).Value = TextBox4.Text.Trim();
行 34: conn.Open();
行 35: cmd.ExecuteNonQuery();
行 36:
源文件: F:\360data\重要数据\我的文档\Visual Studio 2010\Projects\ADO\ADO\Default.aspx.cs 行: 34
堆栈跟踪:
[InvalidOperationException: 实例失败。]
System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity) +5062694
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) +129
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) +164
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +195
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +232
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +185
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +33
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +524
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +479
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +108
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126
System.Data.SqlClient.SqlConnection.Open() +125
ADO._Default.Button2_Click(Object sender, EventArgs e) in F:\360data\重要数据\我的文档\Visual Studio 2010\Projects\ADO\ADO\Default.aspx.cs:34
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112