Results 1 to 4 of 4

Thread: Quick VB .Net Question

  1. #1
    Senior Member crazyfool's Avatar
    Join Date
    Jan 2008
    Posts
    761
    Thanks
    77
    Thanked
    38 times in 38 posts
    • crazyfool's system
      • Motherboard:
      • Striker Extreme
      • CPU:
      • Q6600
      • Memory:
      • OCZ 6400 2 x 2GB
      • Storage:
      • Samsung Spinpoint 500GB
      • Graphics card(s):
      • BFG 8800 GT OC 512MB
      • PSU:
      • Coolermaster Real Power Pro 850w
      • Case:
      • Coolermaster CM-690
      • Operating System:
      • XP, Vista, Windows 7 & Ubuntu
      • Monitor(s):
      • Samsung 2232BW

    Quick VB .Net Question

    hey guys,
    I'm about halfway through my project now and need a little help with this annoying problem. I have written the code to edit a database, add new records etc... All of this works perfectly, however, it works perfectly is i use this connection string for the database
    con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Project.mdb"
    however I don't want to have to limit the install options to one directory so i'm trying to set the connection string like this
    con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Project.mdb"
    my problem is giving the full path to the database works but using "|DataDirectory|\Project.mdb" doesn't work. I dont get an error or anything but when i check the database the relevant records haven't been added or changed... anyone have any ideas?

  2. #2
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts

    Re: Quick VB .Net Question

    Quote Originally Posted by crazyfool View Post
    All of this works perfectly, however, it works perfectly is i use this connection string for the database
    Isn't hard coding the connection string rather limiting anyway

    Is the extra slash necessary?
    To err is human. To really foul things up ... you need a computer.

  3. #3
    Registered+
    Join Date
    Jan 2009
    Posts
    50
    Thanks
    0
    Thanked
    5 times in 4 posts

    Re: Quick VB .Net Question

    Isn't hard coding the connection string rather limiting anyway
    If I read correctly CrazyFool, is referring the install options as a whole. I think he want to decide where the application is to be installed but still wants the MDB to be located with the application. This being the case, using the string in the format he has described would fit.

    If he is looking to install the MDB somewhere completely different.. he would be looking to override the structure of the connection string.

    Is the extra slash necessary?
    Yes.. the DataDirectory returned the location and the last bit indicates the file, using the slash to complete the previous section.

    If you add use the "Data Source Configuration Wizard" to build a connection string, you will see something similar to this being created in the App.Config file of a Windows Form Application.

    CrazyFool, if you don't mind could I ask how you are checking for errors? You may be getting a silent exception? check you have covered all the exceptions and not hiding one, or ignoring the result.

    Have you tried to use the first connection string after renaming/removing the MDB file? If you don't get any errors they you will see straight away that an exception somewhere has not been caught.

    I'm not saying this is the case here, but I have seen people use an Access Db, and reference it in an VB.net application.. forgetting that they answered a prompt to copy the MDB to the project. Thus they actually had several copies of the DB. the Original, the one in the Application folder and one in the Bin directory of the debug folder during testing. When opening the DB to check the data.. they were actually looking at a different copy of the DB... Again.. not saying this is the case, but worth checking.

    Hope this helps.

  4. #4
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts

    Re: Quick VB .Net Question

    I still wouldn't hard code it, in case I was using a different path, or different DB engine entirely in the future, with Access that almost seems a certainty .
    To err is human. To really foul things up ... you need a computer.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. just a quick refund question
    By loki in forum SCAN.care@HEXUS
    Replies: 0
    Last Post: 02-09-2008, 07:32 PM
  2. Just a quick question re DFI LP DK X48 T2R
    By spiderdany in forum SCAN.care@HEXUS
    Replies: 0
    Last Post: 19-08-2008, 06:37 PM
  3. Quick Question - Just placed an order...
    By fonz_valo in forum SCAN.care@HEXUS
    Replies: 3
    Last Post: 01-08-2008, 10:05 AM
  4. Quick Question: PSU's with 1x120mm fan question
    By philyau in forum PC Hardware and Components
    Replies: 10
    Last Post: 05-09-2005, 02:30 PM
  5. Quick Linux question from a newbie...
    By madmonkey in forum Software
    Replies: 19
    Last Post: 26-08-2005, 09:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •