vs2008连sqlserver2008,请高手指点
程序代码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; namespace ConsoleApplication5 { class Program { static void Main(string[] args) { try { string strcon = @"server=localhost;database=Test;uid=sa;pwd=sa"; SqlConnection sqlconn = new SqlConnection(strcon); SqlCommand sqlcomm = sqlconn.CreateCommand(); string commStr = "select * from student"; = commStr; sqlconn.Open(); SqlDataReader myDateReader = sqlcomm.ExecuteReader(); myDateReader.Read(); Console.WriteLine("asdfasd"); Console.ReadLine(); sqlconn.Close(); } catch (Exception e) { // MessageBox.Show("连接错误" + e.ToString()); Console.WriteLine(e.ToString()); } finally { Console.ReadLine(); } } } } 运行结果 System.Data.SqlClient.SqlException (0x80131904): 用户 'sa' 登录失败。原因: 未与 信任 SQL Server 连接相关联。 在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception , Boolean breakConnection) 在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() 在 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cm dHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, Tds ParserStateObject stateObj) 在 System.Data.SqlClient.(Boolean enlis tOK) 在 System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeo ut, SqlConnection owningObject) 在 System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection ow ningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) 在 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnecti on owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, St ring newPassword, Boolean redirectedUserInstance) 在 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdent ity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) 在 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOp tions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) 在 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConn ection owningConnection, DbConnectionPool pool, DbConnectionOptions options) 在 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owning Object) 在 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection o wningObject) 在 System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection ownin gObject) 在 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection ow ningConnection) 在 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection ou terConnection, DbConnectionFactory connectionFactory) 在 System.Data.SqlClient.SqlConnection.Open() 在 ConsoleApplication5.Program.Main(String[] args) 位置 D:\C#workspace\Consol eApplication6\ConsoleApplication6\Program.cs:行号 19
老是连不上,但是绑定可以,大家帮忙看看