Connecting to an ODBC DNS Data Source

Posted on 2007-12-02
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);


            // bind and show the results in the grid

            grdResults.DataSource = ds.Tables[0];





Open in new window

Question by:martgriff
  • 3
LVL 19

Expert Comment

ID: 20392342
DSN not dns
LVL 19

Expert Comment

ID: 20392346
LVL 40

Expert Comment

ID: 20392351
Example connection strings can be found here: -

Author Comment

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?
LVL 19

Accepted Solution

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Allow space in this pattern 2 47
Please explain "Multi-Tenant Services" 5 62
Error on Add method 1 37
Filename to be appended with DateTimeof Download 3 43
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now