How to declare a connectionstring?

Posted on 2014-01-29
Last Modified: 2014-01-29

I have this below to create a button in my application to give the user the ability to compact the database that is connected to the application.

        private void bbComDb_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
            string AccessConnectionString = Properties.Settings.Default.DBRootConnectionString;
            AccessConnectionString.Close(); <=====================

        public static void CompactAccessDB()
                string File_Path;
                string compact_file;
                File_Path = Application.StartupPath + "DBRoot.mdb";
                compact_file = Application.StartupPath + "DBRoot.mdb";
                if (File.Exists(File_Path))
                    JRO.JetEngine objJet = new JRO.JetEngine();
                    objJet.CompactDatabase(File_Path, compact_file);
                if (File.Exists(compact_file))
                    File.Move(compact_file, File_Path);
            catch (Exception ex)

Open in new window

But i get error declaring the connectionstring in the Settings.settings file:

'string' does not contain a definition for 'Close' and no extension method 'Close' accepting a first argument of type 'string' could be found (are you missing a using directive

I have marked the errors with an arrow.

Who can help me?


peter Kiers
Question by:peterkiers
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
  • 2
  • 2
LVL 25

Expert Comment

by:Luis Pérez
ID: 39817399
You're calling a "Close" method on a string. You must close the connection, not the connection string.

I mean, if you want to close a database, I guess you have it open. Where is your database? In the code you provided there is no database, only the connection string stored in a string value.

Author Comment

ID: 39817403
The DB is stored in the application folder:
Application.StartupPath + "DBRoot.mdb";

And de connectionstring is stored in het settings.settings file:

LVL 25

Accepted Solution

Luis Pérez earned 500 total points
ID: 39817406
Well, what I'm trying to say is that you cannot close a connection string. You can close an open connection to the database. Where is that connection? You must be working with it in order to show data from your db into your app and vice versa.

Author Comment

ID: 39817409
Got it. Your right Luis. I have found it and solved it myself. Thanks for the information.

Greetings, Peter kiers

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

732 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