We help IT Professionals succeed at work.
Get Started

Set a string that can be access from the entire winform.

SmashAndGrab asked
Last Modified: 2016-04-28
Hi Experts,

I have a winform that currently uses MS access as its database.  I am in the process of converting the database to SQL compact.

My current method of accessing the Access database is that I set a string at the beginning of the application and use it throughout the App.

see here:

//set the Connection String at the top of the app so it is accessible throughout the application.

 string conn1 = "Provider=Microsoft.JET.OLEDB.4.0;data source=C:\\Users\\Public\\Documents\\MCRS\\Resources\\DB\\MCRS_Data.mdb";

string conn2 = "Provider=Microsoft.JET.OLEDB.4.0;data source=C:\\Users\\Public\\Documents\\MCRS\\Resources\\DB\\MCRS_OTHER.mdb";

public WhateverTheFunctionIs() {

//call the connection string when accessing the database

   OleDbConnection objConn = new OleDbConnection(conn1 ));[/b]

            OleDbDataAdapter objComm = new OleDbDataAdapter("select Company + ',' + username AS MerchID,FullName, AD_Name from MCRS_LU_Users where active like 'y' and Merchandiser like 'y'", objConn);


Open in new window

My SQL Lite db is within the resources folder.
My Question is this:

How do I do the same with my SQL Compact database?
Watch Question
Technology Generalist
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE