Solved

How to declare a connectionstring?

Posted on 2014-01-29
4
267 Views
Last Modified: 2014-01-29
Hi,

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(); <=====================
            CompactAccessDB();
            AccessConnectionString.Open();<=====================
        }
        

        public static void CompactAccessDB()
                {
            try
            {
                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.Delete(File_Path);
                    File.Move(compact_file, File_Path);
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message);
            }
        }

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?

Greetings,

peter Kiers
0
Comment
Question by:peterkiers
  • 2
  • 2
4 Comments
 
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.
0
 
LVL 1

Author Comment

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

And de connectionstring is stored in het settings.settings file:
Properties.Settings.Default.DBRootConnectionString

P.
0
 
LVL 25

Accepted Solution

by:
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.
0
 
LVL 1

Author Comment

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

Greetings, Peter kiers
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 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

19 Experts available now in Live!

Get 1:1 Help Now