Exception error generated when accessing Access database

G

Guest

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");
}
 
K

Kevin Yu [MSFT]

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."
 
H

Hans Kesting

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
 
G

Guest

Thank you very much. This was indeed the solution to my problem.
--
-----------
Thanks,
Steve


Hans Kesting said:
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
 

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

Top