Sunday, March 25, 2012

DataSet.xsd Path in App Config?

Hey all... what is the proper method for setting a Dataset.xsd path in your Settings.settings value:

Here's the app.config from settings.settings value:

<add name="ffgsCRM.My.MySettings.ffgscrmConnectionStringSQLCE"

connectionString="Data Source = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)\ffgsCRM.sdf"

providerName="Microsoft.SqlServerCe.Client" />

I have the above and wondered how to make the path dynamic to C:\Documents and Settings\USERNAME\Local Settings\Application Data\ffgsCRM.sdf in the settings.settings value.

Thanks a ton!!

Bill

I think what you want is to use the |DataDirectory| substitution. Eg "Data Source = |DataDirectory|\ffgsCRM.sdf"|||Thanks... but that only puts the .sdf in the bin and not where I need it. :)|||

To set the DataDirectory property, call the AppDomain.SetData method. If you do not set the DataDirectory property, the following default rules are applied to access the database folder:

?

For applications that are put in a folder on the user's computer, the database folder uses the application folder.

?

For applications that are running under ClickOnce, the database folder uses the specific data folder that is created.

Note The .NET Compact Framework does not support the AppDomain.SetData method on Microsoft Windows Mobile-based devices. If an application calls the AppDomain.SetData method on a Windows Mobile-based device, you receive an error message.

(from http://support.microsoft.com/kb/920700)

|||

|||

To be honest I think you missed the point that both Erik and I were making with the DataDirectory in the when you deploy using ClickOnce it will automatically set the path to the users docs & settings folder.

w.r.t making the dataset dynamic - you can always set the connection object on each of the tableadapters that are used to fill the dataset?

|||

Nick, I'm wrong and had an error in the deployment... sorry... I'm going to try and path the Dataset1 to the users c:\drive\somewhere and go from there.

Thanks,

Bill

|||

my bad...

|||Yea, but where to you use the call to AppDomain.SetData? I call it in the load routine of my start up form, and my data is still being directed to a data folder from the click once deployment, and not to the place I want it in my application executable folder. ? what the ?|||

I did a public in the main form that looks like this for my dataset.xsd:

Public CRMConnectionString As String = "Data Source = " & Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) & "\CRM.sdf"

Now when my app is fired up or deployed the dataset looks for the local db that is in the users program files folder... works all the time as long as you have the local db in the folder.

Hope this helps,

Bill