469,926 Members | 2,090 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,926 developers. It's quick & easy.

Exception error generated when accessing Access database

I am writing my first database application. I am unable to even get to first
base because I can't seem to access the data in the database. Each time the
"Fill" command is executed I get an exception ["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)"]. Does anyone know
why this may be? The database has only two small tables and I am just trying
to access the first table. I have already enabled Remote connections on my
system.

private void GetData()
{
// Specify a connection string.
string connectionString = "Integrated Security=SSPI;Initial
Catalog=ClassData;Data Source=localhost";
SqlConnection connection = new SqlConnection(connectionString);

// Create a DataSet.
DataSet data = new DataSet();
data.Locale = System.Globalization.CultureInfo.InvariantCulture;

// Add data from the Customers table to the DataSet.
SqlDataAdapter masterDataAdapter = new SqlDataAdapter("select * from
Concepts", connection);
masterDataAdapter.Fill(data, "Concepts");
}

--
-----------
Thanks,
Steve
Apr 10 '06 #1
3 2255
Hi Steve,

As far as I know, SQL server 2005 does not allow remote connections by
default. You can try to enable it through the following steps:

1. Start -> Programs -> Microsoft SQL Server 2005 -> Configuration Tools ->
SQL Server 2005 Surface Area Configuration.
2. Click Surface Area Configuration for Services and Connections.
3. In the left treeview, navigate to (Instance)/Database Engine/Remote
Connections.
4. In the right pane, select Local and remote connections, and enable
TCP/IP or named pipes according to your requirements.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Apr 10 '06 #2
> I am writing my first database application. I am unable to even get to first
base because I can't seem to access the data in the database. Each time the
"Fill" command is executed I get an exception ["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)"]. Does anyone know
why this may be? The database has only two small tables and I am just trying
to access the first table. I have already enabled Remote connections on my
system.

private void GetData()
{
// Specify a connection string.
string connectionString = "Integrated Security=SSPI;Initial
Catalog=ClassData;Data Source=localhost";
SqlConnection connection = new SqlConnection(connectionString);

// Create a DataSet.
DataSet data = new DataSet();
data.Locale = System.Globalization.CultureInfo.InvariantCulture;

// Add data from the Customers table to the DataSet.
SqlDataAdapter masterDataAdapter = new SqlDataAdapter("select * from
Concepts", connection);
masterDataAdapter.Fill(data, "Concepts");
}


You are trying to use an Access database? Then you should not use the
SqlConnection and other Sql* objects, as they are specifically for
SqlServer.
You need to use OleDbConnection and it's friends from the
System.Data.OleDb namespace.
The connection string would be something like
"Provider=Microsoft.Jet.OLEDB.4.0; data source={full filename};
user id={loginname}; password={password};"

where the {} parts are replaced (including the {} ) by the correct
values.

Hans Kesting
Apr 10 '06 #3
Thank you very much. This was indeed the solution to my problem.
--
-----------
Thanks,
Steve
"Hans Kesting" wrote:
I am writing my first database application. I am unable to even get to first
base because I can't seem to access the data in the database. Each time the
"Fill" command is executed I get an exception ["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)"]. Does anyone know
why this may be? The database has only two small tables and I am just trying
to access the first table. I have already enabled Remote connections on my
system.

private void GetData()
{
// Specify a connection string.
string connectionString = "Integrated Security=SSPI;Initial
Catalog=ClassData;Data Source=localhost";
SqlConnection connection = new SqlConnection(connectionString);

// Create a DataSet.
DataSet data = new DataSet();
data.Locale = System.Globalization.CultureInfo.InvariantCulture;

// Add data from the Customers table to the DataSet.
SqlDataAdapter masterDataAdapter = new SqlDataAdapter("select * from
Concepts", connection);
masterDataAdapter.Fill(data, "Concepts");
}


You are trying to use an Access database? Then you should not use the
SqlConnection and other Sql* objects, as they are specifically for
SqlServer.
You need to use OleDbConnection and it's friends from the
System.Data.OleDb namespace.
The connection string would be something like
"Provider=Microsoft.Jet.OLEDB.4.0; data source={full filename};
user id={loginname}; password={password};"

where the {} parts are replaced (including the {} ) by the correct
values.

Hans Kesting

Apr 10 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Wayno | last post: by
4 posts views Thread by Charlie Williams | last post: by
4 posts views Thread by maricel | last post: by
5 posts views Thread by Santiago Ordax Solivellas | last post: by
7 posts views Thread by Chuck Hartman | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.