error while establishing a connection to the server

G

Guest

Using Vs2005 sqlServer 2005

When i try to connect i get this error:
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 Interfaces, error: 26 - Error Locating Server/Instance
Specified)

Connection string:
<connectionStrings>
<add name="pubsConnectionString1" connectionString="Data Source=.;Initial
Catalog=pubs;User=mk;pw=x"
providerName="System.Data.SqlClient" />
</connectionStrings>

Calling code :

try
{
using (SqlConnection cn = new
SqlConnection(WebConfigurationManager.ConnectionStrings[0].ConnectionString))
{
cn.Open();

}

}
catch (Exception ex)
{
Response.Write(ex.Message);
}
 
G

Guest

First, you need to determine whether "." (the local machine) is indeed valid
for that SQL Server instance. For example, it may actually be something like
".\SQLNAME".
Also, ensure the userid and password are correct, and that both Windows and
SQL Server authentication are enabled on the SQL Server.
Peter
 
G

Guest

I just created a new site, i added a strongly typed ds to the app_data, the
connection string that was pub in my webconfig is:

<connectionStrings>
<add name="NorthwindConnectionString" connectionString="Data
Source=.;Initial Catalog=Northwind;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>

and this works

so i created this code,,, and it works, thanks

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class ErrPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
string s = "Data Source=.;Initial Catalog=Northwind;Integrated
Security=True";
SqlConnection cn = new SqlConnection(s);
cn.Open();
Response.Write(cn.State);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}

}
}


Peter Bromberg said:
First, you need to determine whether "." (the local machine) is indeed valid
for that SQL Server instance. For example, it may actually be something like
".\SQLNAME".
Also, ensure the userid and password are correct, and that both Windows and
SQL Server authentication are enabled on the SQL Server.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




thom said:
Using Vs2005 sqlServer 2005

When i try to connect i get this error:
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 Interfaces, error: 26 - Error Locating Server/Instance
Specified)

Connection string:
<connectionStrings>
<add name="pubsConnectionString1" connectionString="Data Source=.;Initial
Catalog=pubs;User=mk;pw=x"
providerName="System.Data.SqlClient" />
</connectionStrings>

Calling code :

try
{
using (SqlConnection cn = new
SqlConnection(WebConfigurationManager.ConnectionStrings[0].ConnectionString))
{
cn.Open();

}

}
catch (Exception ex)
{
Response.Write(ex.Message);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top