菜鸟请教 做project的时候出现一个问题,把我给堵了。请教一下各位。
怎么解决啊???头疼...Server Error in '/OSWebSites' Application.
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Inte易做图ces, error: 26 - Error Locating Server/Instance Specified)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Inte易做图ces, error: 26 - Error Locating Server/Instance Specified)
Source Error:
Line 11: command.CommandType = CommandType.StoredProcedure
Line 12: ' Open the connection
Line 13: connection.Open()
Line 14: ' Return a SqlDataReader to the calling function
Line 15: Return command.ExecuteReader(CommandBehavior.CloseConnection)
Source File: C:\Documents and Settings\MaoMao\My Documents\Visual Studio 2008\OSWebSites\App_Code\Catalog.vb Line: 13
Stack Trace:
[SqlException (0x80131904): An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Inte易做图ces, error: 26 - Error Locating Server/Instance Specified)]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +800131
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +186
System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject) +737554
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +114
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +421
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +181
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +173
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +357
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +30
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +424
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +494
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +82
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105
System.Data.SqlClient.SqlConnection.Open() +111
Catalog.GetDepartments() in C:\Documents and Settings\MaoMao\My Documents\Visual Studio 2008\OSWebSites\App_Code\Catalog.vb:13
UserControls_WebUserControl.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\MaoMao\My Documents\Visual Studio 2008\OSWebSites\UserControls\DepartmentsList.ascx.vb:20
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436
Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433
--------------------编程问答-------------------- 你连接的是远程数据库码? --------------------编程问答-------------------- 不是,本地的. --------------------编程问答-------------------- 不是,本地的. --------------------编程问答-------------------- 把相关代码贴上来看看吧 --------------------编程问答-------------------- Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports System.Data
Public Class Catalog
Public Shared Function GetDepartments() As SqlDataReader
Dim connection As New SqlConnection(connectionString)
Dim command As New SqlCommand("GetDepartments", connection)
command.CommandType = CommandType.StoredProcedure
connection.Open()
Return command.ExecuteReader(CommandBehavior.CloseConnection)
End Function
Private Shared ReadOnly Property connectionString() As String
Get
Return ConfigurationSettings.AppSettings("ConnectionString")
End Get
End Property
End Class --------------------编程问答-------------------- GetDepartments 这个函数是如何调用的? --------------------编程问答-------------------- Return command.ExecuteReader(CommandBehavior.CloseConnection)
这样返回datareader是不对的。我在本机上测试会报错。
command.ExecuteReader 这种command类型不应该是Procedure --------------------编程问答-------------------- up --------------------编程问答-------------------- 我这边倒不是其他的问题,就是connection.Open() 报错,刚才贴的就是报错的信息 --------------------编程问答-------------------- connectionString 那把这个内容贴上来吧。还有即使你在这里报错,但是到下面还会报错的 --------------------编程问答-------------------- 我在web.config里面add key
<appSettings >
<add key ="ConnectionString" value ="Server=(local)\NetSDK;Integrated Security = True;Initial Catalog=Shop"/>
</appSettings> --------------------编程问答-------------------- 连接字符串里怎么没有workstation id呢?添加上去看看
可以看看这里的连接字符串介绍www.connectionstrings.com --------------------编程问答-------------------- 好的,谢谢您啊,我现在就去看看
补充:.NET技术 , VB.NET