sqlexception was unhandled by user code

I am  executing web application using MS VS 2008 and Ms Access 2007
but it shows error
sqlexception was unhandled by user code (line no 13)
(provider: SQL Network Interfaces, error: 25 - Connection string is not valid)
=======================web.config code ==================
    <add name="TestConnectionString" connectionString="Data Source=\app_data\SMOSYS.accdb;"
      providerName="Microsoft.Jet.OLEDB.4.0" />
========================= An error occurred while running code============
public bool Validate(string usrId, string pwd)
        bool status = false;

        cmdString = "SELECT * FROM Login WHERE IsActive='1'";
        dataAdapter = new OLEDBDataAdapter(cmdString, connectionString);
        dataAdapter.Fill(dataSet);               //sqlexception was unhandled by user code 
        dataTable = dataSet.Tables[0];

Open in new window

prashanth agsoftware engineer Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lokesh B RDeveloperCommented:

You need to Use OLE DB Provider to connect to the Access database.

Check the sample code here

protected void Page_Load(object sender, EventArgs e)
            if (!IsPostBack)
                string accessConnectionString = ConfigurationManager.ConnectionStrings["accessConnectionString"].ConnectionString;

                using (OleDbConnection con = new OleDbConnection(accessConnectionString))
                    string query = "SELECT * FROM Login WHERE IsActive='1';";
                    OleDbCommand cmd = new OleDbCommand(query, con);
                    OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                    DataSet ds = new DataSet();

Open in new window


Make sure your accdb file is in App_Data folder.

    <add name="accessConnectionString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\SMOSYS.accdb;Persist Security Info=True"/>

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kamal KhaleefaInformation Security SpecialistCommented:
you are not setting the connection string

you need to call the value from web.config and pass it to your code
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.