I am trying to make a simple connection to my sql server, but am getting an error. I am not sure why it says SQL Server 2005 in the error as we use 2000. I have found others to have the problem on the web, but have found no answers. One person said the sql connection worked when he downgraded to 1.1; however, I'd like to avoid that. Here is my code:
<%
@.ImportNamespace="System.Data.SqlClient" %><
scriptrunat="server">Sub Page_Load()Dim conNorthwindAs SqlConnection
conNorthwind =
New SqlConnection("Server=1CDRSRV4; uid=username; pwd=password; database=Northwind")conNorthwind.Open()
EndSub</
script><
htmlxmlns="http://www.w3.org/1999/xhtml"><
headrunat="server"><
title>Untitled Page</title></
head><
body>Connection Opened!
</
body></
html>
here is my error:
Server Error in '/' 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Source Error:
Line 6: Line 7: conNorthwind = New SqlConnection("Server=1CDRSRV4; uid=sa; pwd=sa; database=Northwind")Line 8: conNorthwind.Open()Line 9: End SubLine 10: </script>
Source File:C:\Inetpub\wwwroot\chap2\sqlconnection.aspx Line:8
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)] System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +734995 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188 System.Data.SqlClient.TdsParser.Connect(Boolean& useFailoverPartner, Boolean& failoverDemandDone, String host, String failoverPartner, String protocol, SqlInternalConnectionTds connHandler, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject, Boolean aliasLookup) +820 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +628 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +170 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +359 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +28 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +424 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66 System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +496 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +82 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105 System.Data.SqlClient.SqlConnection.Open() +111 ASP.chap2_sqlconnection_aspx.Page_Load() in C:\Inetpub\wwwroot\chap2\sqlconnection.aspx:8 System.Web.Util.CalliHelper.ArglessFunctionCaller(IntPtr fp, Object o) +5 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +783999 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +47 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.210
A little more information:
I'm basically learning the language again and I have it set up on my local machine (localhost), but connecting to an existing sql 2000 server if that helps at all.
Also, when I use visual studio to create the connection, the following code seems to work:
<
htmlxmlns="http://www.w3.org/1999/xhtml"><
headrunat="server"><title>Untitled Page</title></
head><
body><formid="form1"runat="server"><div> <asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="Data Source=CDRSRV4;Initial Catalog=Northwind;Persist Security Info=True;User ID=sa;Password=sa"SelectCommand="SELECT * FROM [Alphabetical list of products]"></asp:SqlDataSource></div></form>
</
body></
html>|||It has to be something to do with using localhost because when I use our live web server, it appears to connect fine.|||Hi
I am afraid you are using vs2005 and its default database is sql server 2005 so the error message means if you are connecting sql server 2005 this failure may be caused by the fact that ....
Since your connection string works fine ,make sure Named Pipes and TCP/IP network libraries are enabled for the SQL2000 instance.
Hope it helps.
No comments:
Post a Comment