首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

百分求救asp.net2005连接sql2005时出错,该怎么处理

2012-01-21 
百分求救asp.net2005连接sql2005时出错在App_Code目录下,有文件BDcode.vbImportsSystem.Data.SqlClientImp

百分求救asp.net2005连接sql2005时出错
在App_Code目录下,有文件BDcode.vb
Imports   System.Data.SqlClient
Imports   System.IO

Namespace   Library

        Public   Class   BDcode
                Private   connectingstring   As   String
                Private   myConn   As   SqlConnection
                Private   myAdapter   As   SqlDataAdapter
                Private   myCmd   As   SqlCommand

                Public   Sub   New()
                        connectingstring   =   System.Configuration.ConfigurationManager.AppSettings( "DSN_manage ").ToString.Trim
                        myConn   =   New   SqlConnection(connectingstring)
                End   Sub
                Public   Sub   Open()
                        myConn.Open()
                End   Sub
                Public   Sub   Close()
                        myConn.Close()
                End   Sub
                '=============================================================
                '   函   数   名:ExecNonSql
                '   功能描述:执行无返回值的数据库操作
                '   输入参数:sqlstr,查询的SQL字符串
                '   返   回   值:无
                '   创建日期:
                '   修改日期:
                '   作         者:
                '   附加说明:
                '==============================================================
                Public   Sub   ExecNonOleDb(ByVal   sqlstr   As   String)
                        myCmd   =   New   SqlCommand(sqlstr,   myConn)
                        myCmd.ExecuteNonQuery()
                        myCmd.Dispose()
                        Close()
                End   Sub
                Public   Function   ExecReaderSql(ByVal   sqlstr   As   String)   As   SqlDataReader
                        myCmd   =   New   SqlCommand(sqlstr,   myConn)


                        Dim   reader   As   SqlDataReader
                        reader   =   myCmd.ExecuteReader
                        myCmd.Dispose()
                        Return   reader
                End   Function

        End   Class
End   Namespace

但在调用Open时出错
用户代码未处理   System.Data.SqlClient.SqlException
    Class=20
    ErrorCode=-2146232060
    LineNumber=0
    Message= "在建立与服务器的连接时出错。在连接到   SQL   Server   2005   时,在默认的设置下   SQL   Server   不允许进行远程连接可能会导致此失败。   (provider:   命名管道提供程序,   error:   40   -   无法打开到   SQL   Server   的连接) "
    Number=2
    Server= " "
    Source= ".Net   SqlClient   Data   Provider "
    State=0
    StackTrace:
              在   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException   exception,   Boolean   breakConnection)
              在   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject   stateObj)
              在   System.Data.SqlClient.TdsParser.Connect(ServerInfo   serverInfo,   SqlInternalConnectionTds   connHandler,   Boolean   ignoreSniOpenTimeout,   Int64   timerExpire,   Boolean   encrypt,   Boolean   trustServerCert,   Boolean   integratedSecurity,   SqlConnection   owningObject)
              在   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo   serverInfo,   String   newPassword,   Boolean   ignoreSniOpenTimeout,   Int64   timerExpire,   SqlConnection   owningObject)
              在   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String   host,   String   newPassword,   Boolean   redirectedUserInstance,   SqlConnection   owningObject,   SqlConnectionString   connectionOptions,   Int64   timerStart)
              在   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection   owningObject,   SqlConnectionString   connectionOptions,   String   newPassword,   Boolean   redirectedUserInstance)
              在   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity   identity,   SqlConnectionString   connectionOptions,   Object   providerInfo,   String   newPassword,   SqlConnection   owningObject,   Boolean   redirectedUserInstance)
              在   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions   options,   Object   poolGroupProviderInfo,   DbConnectionPool   pool,   DbConnection   owningConnection)
              在   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection   owningConnection,   DbConnectionPool   pool,   DbConnectionOptions   options)


              在   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection   owningObject)
              在   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection   owningObject)
              在   System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection   owningObject)
              在   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection   owningConnection)
              在   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection   outerConnection,   DbConnectionFactory   connectionFactory)
              在   System.Data.SqlClient.SqlConnection.Open()
              在   Library.BDcode.Open()   位置   D:\xinxiang\App_Code\BDcode.vb:行号   17
              在   manage_login.Button1_Click(Object   sender,   EventArgs   e)   位置   D:\xinxiang\login.aspx.vb:行号   20
              在   System.Web.UI.WebControls.Button.OnClick(EventArgs   e)
              在   System.Web.UI.WebControls.Button.RaisePostBackEvent(String   eventArgument)
              在   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String   eventArgument)
              在   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler   sourceControl,   String   eventArgument)
              在   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection   postData)
              在   System.Web.UI.Page.ProcessRequestMain(Boolean   includeStagesBeforeAsyncPoint,   Boolean   includeStagesAfterAsyncPoint)


[解决办法]
连接字符串有问题或者Sql2005的Tcp/IP服务没有打开。如果是本机地话直接在连接字符串那里的服务器地址设置为.,不要用IP
[解决办法]
检查一下连接字符串.
[解决办法]
应该是连接字符串的问题
[解决办法]
(1)服务器没有打开或者连接字符串的有问题

(2) "开始 "-> "程序 "-> "Microsoft SQL Server 2005 "-> "配置工具 "-> "SQL Server 外围应用配置器 "-> 选择 "服务连接的外围应用配置器 "
这时候打开 "服务连接的外围应用配置器 " 在 "服务 "选项中,把启动类型设为-> "自动 "
在 "远程连接 "选项中,单选 "本地连接和远程连接 "---> "同时使用TCP/IP和named pipes "--> 点击 "应用 "-----> 回到 "服务 "选项中 "--> 重新启动外围应用配置器 "就行了

你的情况应该是第二种:
[解决办法]
启动sql2005,在控制面板-> 计算机管理-> 服务里面,把sql2005服务开启

热点排行