当前位置:编程学习 > C#/ASP.NET >>

请教大虾一个问题


运行下面一个程序
using System;
using System.Data.SqlClient;

namespace ADO_SqlConnection
{
     class T
     {
         public void CreateSqlConnection()
         {
             SqlConnection myCon = new SqlConnection();
             myCon.ConnectionString = "Persist Security Info=False;User id=sa;pwd=850792195;database=northwind;;server=(.)";
             myCon.Open();  
             Console.WriteLine("{0}", myCon.State);     //输出:Open
             myCon.Close();
             Console.WriteLine("{0}", myCon.State);     //输出:Closed
         }

         static void Main(string[] args)
         {
             T t = new T();
             t.CreateSqlConnection();
         }
     }
}




为什么显示如下信息


未经处理的异常:   System.Data.SqlClient.SqlException: Timeout 时间已到。在操作完
成之前超时时间已过或服务器未响应。
    在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception
, Boolean breakConnection)
    在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
    在 System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObje
ct stateObj, UInt32 error)
    在 System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult asyncResu
lt, TdsParserStateObject stateObj)
    在 System.Data.SqlClient.TdsParserStateObject.ReadNetworkPacket()
    在 System.Data.SqlClient.TdsParser.ConsumePreLoginHandshake(Boolean encrypt,
Boolean trustServerCert, Boolean& marsCapable)
    在 System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternal
ConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Bool
ean encrypt, Boolean trustServerCert, Boolean integratedSecurity)
    在 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()
    在 ADO_SqlConnection.T.CreateSqlConnection() 位置 C:\BegVCSharp\Chapter2\Cons
oleApplication9\ConsoleApplication9\Program.cs:行号 12
    在 ADO_SqlConnection.T.Main(String[] args) 位置 C:\BegVCSharp\Chapter2\Consol
eApplication9\ConsoleApplication9\Program.cs:行号 21
请按任意键继续. . .
 
--------------------编程问答-------------------- 没有连接数数据库,检查连接信息,服务器地址,用户名和密码,还有网络是否通畅等 --------------------编程问答-------------------- sql连接超时 --------------------编程问答-------------------- 数据库没有连接上,sql的服务是否开启. --------------------编程问答--------------------
引用 1 楼 bdmh 的回复:
没有连接数数据库,检查连接信息,服务器地址,用户名和密码,还有网络是否通畅等


+1

大体上有这些问题!
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,