Showing posts with label aspx. Show all posts
Showing posts with label aspx. Show all posts

Thursday, March 22, 2012

error: 40 - Could not open a connection to SQL Server

I have created a new aspx site on 'server 1' which connects to an sql server 200 on 'server 2' 'Server 1' is a test server and all works fine. I then move the site onto 'server 3' and receive the error below.

This must be a problem with 'server 3'. I have installed .net version 2 on this server and there are currently no aspx sites running of this server. There must be smothering not configured right. There are other sites on the server that are talking to the SQL server.

Any help would be great.

Thanks

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:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


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) +735059
  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
  System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +121
  System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +137
  System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +83
  System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1770
  System.Web.UI.WebControls.Repeater.GetData() +50
  System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +232
  System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +53
  System.Web.UI.WebControls.Repeater.DataBind() +72
  System.Web.UI.WebControls.Repeater.EnsureDataBound() +55
  System.Web.UI.WebControls.Repeater.OnPreRender(EventArgs e) +12
  System.Web.UI.Control.PreRenderRecursiveInternal() +77
  System.Web.UI.Control.PreRenderRecursiveInternal() +161
  System.Web.UI.Control.PreRenderRecursiveInternal() +161
  System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360

Hi,

I also faced same problem. I was using following connection string.

<add name="ConnectionString" connectionString="data source=local;initial catalog=Rainbow;integrated security=True;User ID=;Password="/>

And modified to this.

<add name="ConnectionString" connectionString="data source=localhost;initial catalog=Rainbow;integrated security=True;User ID=;Password="/>

It started working in my case :)-

Regards,

Gaurav Goel

Friday, March 9, 2012

Error. My aspx file cant access server to connect to database

Hi,

I am writing my first aspx file to connect to a standalone SQL Server which is separated from the IIS webserver. The code is

<HTML>
<HEAD>
<TITLE>Store Locator</TITLE>
<script runat="server">
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
if Not IsPostBack Then
Dim DBConn as OleDbConnection
Dim DBCommand As OleDbDataAdapter
Dim DSPageData as New DataSet
DBConn = New OleDbConnection("Provider=sqloledb;" _
& "server=dailyplanet;" _
& "Initial Catalog=JAVSTORE;" _
& "User Id=javtrader;" _
& "Password=rage123;")
DBCommand = New OleDbDataAdapter _
("Select * " _
& "From JAVInventory " _
& "Where ID > ((Select COUNT(ID) " _
& "From JAVInventory ) - 100)" _
& "Order By ID DESC", DBConn)
DBCommand.Fill(DSPageData, _
"RecentJAVs")
' ddlZipCode.DataSource = _
' DSPageData.Tables("RecentJAVs").DefaultView
' ddlZipCode.DataBind()
End If
End Sub

I used Visual .Net and Web Matrix and was able to connect to the sql server with the Data Connection to view the tables. However, when I use IIS or the Visual .Net debugger to run the aspx file, it get the following error.. please help..

Server Error in '/javtrade' Application.
------------------------

[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
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.OleDb.OleDbException: [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.

Source Error:

Line 21: & "From JAVInventory ) - 100)" _
Line 22: & "Order By ID DESC", DBConn)
Line 23: DBCommand.Fill(DSPageData, _
Line 24: "RecentJAVs")
Line 25: ' ddlZipCode.DataSource = _

Source File: c:\inetpub\wwwroot\javtrade\management.aspx Line: 23

Stack Trace:

[OleDbException (0x80004005): [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.]
System.Data.OleDb.OleDbConnection.ProcessResults(Int32 hr)
System.Data.OleDb.OleDbConnection.InitializeProvider()
System.Data.OleDb.OleDbConnection.Open()
System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection, ConnectionState& originalState) +44
System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +304
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +77
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +36
ASP.management_aspx.Page_Load(Object Sender, EventArgs E) in c:\inetpub\wwwroot\javtrade\management.aspx:23
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731FYI, when using sql server it is better to use the sql namespace over the oledb. I assume you have a connection string in your web.config file. This can be formed in two ways, one using a trusted connection, or the other being uid=; and pwd=; the login and password for sql respectively. Either version of the connection string must include the server name, which is localhost, 127.0.0.1 if on the localmachine or the actual name or ip of the server.