Solved

Connecting to an ODBC DNS Data Source

Posted on 2007-12-02
5
1,005 Views
Last Modified: 2012-06-21
I am trying to connect to an Access mdb file using ODBC DNS, Can you please take alook at the code attched and see if you can see where im going wrong.

when i run the web app and press the button that calls the conection i get the following error on "conn.ConnectionString = strConnectionString;":
An OLE DB Provider was not specified in the ConnectionString.  An example would be, 'Provider=SQLOLED

All commects welcome.........................
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.OleDb; // added library
using Microsoft.Data.Odbc; //added libary
 
namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
 
        }
 
        protected void btnGo_Click(object sender, EventArgs e)
        {
 
            // set the connection string
            //note: the @ symbol is needed before the string to prevent from having to use double back slashes
            string strConnectionString = "@DNS=PHJ;Uid=;Pwd=;";
 
                        // get the search contents
            string strSearchValue = txtSearch.Text;
 
            // create the sql query using the search value - note: access over oledb requires square brackets round table name
            string strSql = "SELECT OrderID, ServiceID FROM [Order2Service] WHERE ServiceID LIKE '%" + strSearchValue + "%';";
 
 
            // create a new connection object
            OleDbConnection conn = new OleDbConnection();
 
            // set the connection string from the global variable
            conn.ConnectionString = strConnectionString;
 
            // create a new command object using the connection
            OleDbCommand command = new OleDbCommand();
            command = conn.CreateCommand();
            command.CommandText = strSql; // set the sql query
 
            // create the dataset
            DataSet ds = new DataSet();
 
            // set and run the query - the adaptor executes the command against the database set in the command
            OleDbDataAdapter adapter = new OleDbDataAdapter();
            adapter = new OleDbDataAdapter(command);
            adapter.Fill(ds);
 
            // bind and show the results in the grid
            grdResults.DataSource = ds.Tables[0];
            grdResults.DataBind();
 
        }
    }
}

Open in new window

0
Comment
Question by:martgriff
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 19

Expert Comment

by:weellio
ID: 20392342
DSN not dns
0
 
LVL 19

Expert Comment

by:weellio
ID: 20392346
0
 
LVL 40

Expert Comment

by:evilrix
ID: 20392351
Example connection strings can be found here: -
http://www.connectionstrings.com/?carrier=access
0
 

Author Comment

by:martgriff
ID: 20394375
I have been on that website and if you look at my code i have put what they recommed but it is still failing, i have never connected to an DSN before so im not sure if there is somthing else missing?
0
 
LVL 19

Accepted Solution

by:
weellio earned 500 total points
ID: 20396252
string strConnectionString = "@DNS=PHJ;Uid=;Pwd=;";
should be
string strConnectionString = "@DSN=PHJ;Uid=;Pwd=;";


and it may help to have a userid and password
uid = userid
pwd = password
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question