[dba-VB] Application settings

Charlotte Foust cfoust at infostatsystems.com
Thu Dec 3 18:26:56 CST 2009

Create an xml file called UserSettings (or whatever) and store each value in a node in that.  Then all you have to do is read them back when you need them.  We use several of these, one called OLEDBSettings.xml that looks like this: 

  <?xml version="1.0" standalone="yes" ?> 
- <NewDataSet>
- <connection>
  <datasource>C:\Documents and Settings\All Users\Application Data\Infostat\RIMDrill\5\RIMDrillData.mdb</datasource> 
  <password /> 
  <initialcatalog /> 
- <connection>
  <userid /> 
  <password /> 

We actually have a file like this for each application and it lives in the application folder.  This is just to give you an idea, not a how to.   We have a class that wraps this in our apps and uses this kind of routine to read it.  I leave it up to you to translate to C#.

    Shared ds As DataSet
    Shared _connectionString As String

    Shared _xmlPath As String = "OLEDBSettings.xml"         'default to xml file in apppath

   Private Shared Sub ReadSettingsFile()
        If IO.File.Exists(_xmlPath) Then
            Call CreateSchema()
            Call DecryptPassword()
            _connectionString = GetConnectionString()
            If ds.Tables(0).Rows.Count = 0 Then
                'placeholder for jet settings
                Dim row As DataRow = ds.Tables(0).NewRow
                row("dbtype") = 0
                row("provider") = "Microsoft.Jet.OLEDB.4.0"

                'placeholder for sql settings
                row = ds.Tables(0).NewRow
                row("dbtype") = 1
                row("provider") = "sqloledb"
            End If
        End If
    End Sub

  Private Shared Sub CreateSchema()
        ds = New DataSet
        Dim table As New DataTable("connection")
        table.Columns.Add("dbtype", GetType(Integer))
        table.Columns.Add("provider", GetType(String))
        table.Columns.Add("datasource", GetType(String))
        table.Columns.Add("userid", GetType(String))
        table.Columns.Add("password", GetType(String))
        table.Columns.Add("initialcatalog", GetType(String))
        table.Columns.Add("trusted", GetType(Boolean))
        table.PrimaryKey = New DataColumn() {table.Columns("dbtype")}

    End Sub


-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com [mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of jwcolby
Sent: Thursday, December 03, 2009 3:39 PM
Subject: [dba-VB] Application settings

I want to create application settings for things like the server instance that the program will bang on, the name of my database that I save my custom UDFs and SPs in etc.  It is trivial to get there in the interface but Google is not my friend tonight in discovering how to access / modify them through code.


John W. Colby
dba-VB mailing list
dba-VB at databaseadvisors.com

More information about the dba-VB mailing list