I am developing my first website for my boss. I am trying to connect to an access database which I have created a DSN for on the server. I am using the following code sample...
//Connection String 1
string dsn_name ="access_WALLINVEN.dsn";
string sDSNDir = Server.MapPath("_dsn");
string connectstr = ("Data Source="
+ (sDSNDir + ("\\" + dsn_name)));
//Connection String 2
string connectstr ="Data Source=/jwallpaint/_dsn/access_WALLINVEN.dsn;Uid=jwallpaint;Pwd=J2512wall;";
string commandString ="Select * from Inventory";
//Pass strings to sqlDataAdapter constructor
SqlDataAdapter dataAdapter =newSqlDataAdapter(commandString, connectstr);
//Create a dataset
DataSet dataSet =newDataSet();
//fill the dataset object
dataAdapter.Fill(dataSet,"Inventory");
//Get the table from the dataset
DataTable dataTable = dataSet.Tables["Inventory"];
//Bind to the gridview
GridView1.DataSource = dataTable;
GridView1.DataBind();
For Connection String 1 I get the error of...
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)
For Connection String 2 I get the error of...
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)
I am not sure which connection string to use either...
It is strange to me that I get this error talking about SQL Server when I am trying to reach my Access database.....Any Help?? Thanks...
Connection string forFile DSN:"FILEDSN=c:\myData.dsn;Uid=myUsername;Pwd=;"
Checkhttp://www.connectionstrings.com/ for more connection strings.
No comments:
Post a Comment