Results 1 to 8 of 8

Thread: [RESOLVED] Replace |DataDirectory| or replace with own string.

  1. #1

    Thread Starter
    Member CherryPickle's Avatar
    Join Date
    Aug 2009
    Location
    South Africa
    Posts
    40

    Resolved [RESOLVED] Replace |DataDirectory| or replace with own string.

    Hi

    I would like to allow my users to decide where they want their data to reside. I have created a data source which is referenced by crystal reports. I would like to replace the |DataDirectory| to point to a path the user selects.

    or if possible substitute it with vb function.

    Below is the line in xml that point to my db. I would like to allow it to call a vb function that will return my db path
    I am not sure how to replace the connection string by using a vb function in xml.


    Code:
    <Connection ConnectionStringObject="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\MY_DB.mdb;Persist Security Info=True;Jet OLEDB:Database Password=pass" IsAppSettingsProperty="false" Modifier="Assembly" Name="MY_DB.mdb" Provider="System.Data.OleDb" />
    I would like to replace |DataDirectory| with the result of a function called MyDBPath(), can anyone assist.

  2. #2
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: Replace |DataDirectory| or replace with own string.

    String.Replace is always a good bet.

  3. #3

    Thread Starter
    Member CherryPickle's Avatar
    Join Date
    Aug 2009
    Location
    South Africa
    Posts
    40

    Re: Replace |DataDirectory| or replace with own string.

    What I need to do is to insert a function that gets the path into the xml code.

    In vb I would use:

    Code:
    ConnString = Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MyDBPath() & "\MY_DB.mdb;Persist Security Info=True;Jet OLEDB:Database Password=pass"
    How do I insert that same function into the xml code below?

    Code:
    <Connection ConnectionStringObject="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\MY_DB.mdb;Persist Security Info=True;Jet OLEDB:Database Password=pass" IsAppSettingsProperty="false" Modifier="Assembly" Name="MY_DB.mdb" Provider="System.Data.OleDb" />

  4. #4
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: Replace |DataDirectory| or replace with own string.

    Are you reading from an XML file, is this WPF? You'll have to be a little clearer.

  5. #5

    Thread Starter
    Member CherryPickle's Avatar
    Join Date
    Aug 2009
    Location
    South Africa
    Posts
    40

    Re: Replace |DataDirectory| or replace with own string.

    Sorry, I am new at it, and will try to explain myself better.

    I have used the wizard provided with vs 2008 to connect to a data source. VS automatically created an *.xsd file for the data source. Inside this xsd file is the connection string to my databas. In an attempt to allow the user to place this dataset where he wishes to and still be able to connect to it, I would like to use an existing vb function to provide the database path to the xml code in the *.xsd file.

    Hope this makes it a little clearer.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Replace |DataDirectory| or replace with own string.

    You should keep using |DataDirectory| in your connection string and then simply set the data directory for your AppDomain at startup, e.g.
    vb.net Code:
    1. AppDomain.CurrentDomain.SetData("DataDirectory", My.Settings.DataDirectory)
    You would pass the path chosen by the user as the second argument. You can store it in your application settings, as I've demonstrated, or somewhere else.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: Replace |DataDirectory| or replace with own string.

    Or if you really want to do it on-the-fly every time, you can use a FolderBrowserDialog and pass the SelectedPath property as the second parameter of the method shown by jmcilhinney.

  8. #8

    Thread Starter
    Member CherryPickle's Avatar
    Join Date
    Aug 2009
    Location
    South Africa
    Posts
    40

    Re: Replace |DataDirectory| or replace with own string.

    Thanks jmcilhinney, this realy helped.

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width