473,545 Members | 1,224 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

app.config file connection string when using c# Winforms to MSAccess database

I am unable to get the connection to work with using the app.config
file.
the connection works when I use 'in line' connection as below:
------------------------------------------------------------------
I have a declaration in the class
private OleDbConnection con;

Then code in a procedure as below:
1. This works:
con = new OleDbConnection
("Provider=Micr osoft.Jet.OLEDB .4.0;Password=; User ID=;Data
Source=C:\\Data \\C#Projects\\P roPay\\ProPay.m db;");
con.Open();

2. This does not work:
con = new OleDbConnection (ConfigurationS ettings.AppSett ings["DBConnectionSt ring"]);
con.Open();

The App.config file that is being called here is:

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<appSettings>
<!-- User application and configured property settings go
here.-->
<add key="DBConnecti onString"
value="Provider =Microsoft.Jet. OLEDB.4.0;Passw ord=;User ID=;Data
Source=C:\\Data \\C#Projects\\P roPay\\ProPay.m db;" />
</appSettings>
</configuration>

-----------------------------------------------------------

The error message provided (VisStudio 2003) is:
A first chance exception of type 'System.Invalid OperationExcept ion'
occurred in system.data.dll

Additional information: The ConnectionStrin g property has not been
initialized.
-------------
I have tried using the connection string generated through using oleDB
connection in the Dynamic properties of the OleDBConnection object
that I dragged onto a form. This did not work.
I have tried playing with the syntax a myriad of ways (ie single
backslashes) - no luck.
I used a connection string I generated from oleDBconnection object
dragged onto a form - no luck.
I have called the config file by MYApp.exe.confi g

If someone can point me in the right direction, I would be most
greatful. If there is a site with information relating to Data access
Using C# and MSAccess, this would be great too.
I have not had much joy using parametized queries using
oleDBCommand.Co mmandType.Store dProcedure. Can this be done or can one
only use "texttype?"
I have adapted info from
http://www.csharpfriends.com/Article...px?articleID=3
which relates to data Access and SQL databases but this uses stored
procedures which is where I am not winning.

Thanks in anticipation.

Grant
Nov 15 '05 #1
1 38514

Hello GrantS!

Try app.config with one backslash in path:

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<appSettings>
<!-- User application and configured property settings go
here.-->
<add key="DBConnecti onString"
value="Provider =Microsoft.Jet. OLEDB.4.0;Passw ord=;User ID=;Data
Source=C:\Data\ C#Projects\ProP ay\ProPay.mdb;" />
</appSettings>
</configuration>
--
WBR, Roman S. Golubin
ICQ UIN 63253392
go*****@arhcity .ru

This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
15403
by: Bonj | last post by:
Like a web app can store its connection string in the web.config file, can a windows forms or console app or windows service store its connection string in app.config? Is it advisable? I know the web application is best to store its strings in there as the web server will flatly refuse to serve up that file, but I've heard that it will...
0
2529
by: timandsuzi36 | last post by:
I have a WinForms App that is launching an Access 2003 db Reports program. I am using the System.Diagnostics.Process object to do so. I thought that I could pass my db connection string to Access using the Process.StartInfo.Arguments with the /cmd switch like so. System.Diagnostics.Process i = new System.Diagnostics.Process();...
8
1977
by: Robert | last post by:
I have what I think should be a pretty common scenario in a corporate environment. I have a web app and three environments on three servers: Development, QA and Production. We develop in development and then deploy the updated application to our QA server and then once tested to our production server. The application has a web.config...
14
3482
by: WebMatrix | last post by:
Hello, I have developed a web application that connects to 2 different database servers. The connection strings with db username + password are stored in web.config file. After a code review, one developer suggested that it's a security flaw; therefore connection strings should be kept somewhere else or encrypted. My argument is that...
5
2277
by: Sridhar | last post by:
Hi, I have created a project which contains classes to read the data from the database. This project has an App.Config file which contains the SqlConnection String. when this code is called from a web application and if I need to read the connection string it is reading the connection string from the web.config of web application. I am not...
8
1957
by: theWizard1 | last post by:
Using Asp.NET 1.1, and C#. I have a directory for the website, and a directory under it named Secure. I have a web.config in each of the above directories. The web.config in the Secure directory contains the connection string information for the database. How can I use ConfigurationSettings.AppSettings to show the path of the Secure...
12
13412
by: dbuchanan | last post by:
Hello, (Is this the proper newsgroup?) === Background === I am building a solution with two projects. One project is my data access layer which contains my DataSet as an xsd file. The XSD file was built by draging tables from the Data Sources pane. Auto-generated code created the files associated wtih the XSD file (xss,
0
1816
by: Sergio Montero | last post by:
Hi, I've been googling for a while trying to figure out how to solve this problem, pleasy, I'll appreciate any sugestions. I have a Winforms App that should work Online and Offline. Online Mode. Is the default mode and occurs when the App have an Internet connection. In this mode the App connects to a SQL Server 2005 database using a XML...
2
5376
by: Johnson | last post by:
I'm trying to fix a "sub optimal" situation with respect to connection string management. Your thoughtful responses will be appreciated. I just started with a new client who has a bunch of legacy ASP.NET applications that all manage connection strings in Web.config the same way, like this: This client has one Web.config file per...
0
7465
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7398
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7805
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7416
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5969
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4944
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3449
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.