[dba-VB] Application settings

Michael Maddison michael at ddisolutions.com.au
Thu Dec 3 18:43:32 CST 2009


Hi Charlotte,

I see this as useful, but,
If you need a complex setting structure why not just create a
'MySettings' class and serialise or deserialise it as needed?
I think John has already worked with the Serializable attribute.
Am I missing something?

Cheers

Michael M


-----Original Message-----
From: dba-vb-bounces at databaseadvisors.com
[mailto:dba-vb-bounces at databaseadvisors.com] On Behalf Of Charlotte
Foust
Sent: Friday, 4 December 2009 11:27 AM
To: Discussion concerning Visual Basic and related programming issues.
Subject: Re: [dba-VB] Application settings

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>
  <dbtype>0</dbtype> 
  <provider>Microsoft.Jet.OLEDB.4.0</provider> 
  <datasource>C:\Documents and Settings\All Users\Application
Data\Infostat\RIMDrill\5\RIMDrillData.mdb</datasource> 
  <userid>RIMUser</userid> 
  <password /> 
  <initialcatalog /> 
  <trusted>false</trusted> 
  </connection>
- <connection>
  <dbtype>1</dbtype> 
  <provider>sqloledb</provider> 
  <datasource>infoserver</datasource> 
  <userid /> 
  <password /> 
  <initialcatalog>RIMDrillDataSQL</initialcatalog> 
  <trusted>true</trusted> 
  </connection>
  </NewDataSet>

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()
            ds.ReadXml(_xmlPath)
            Call DecryptPassword()
            _connectionString = GetConnectionString()
        Else
            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"
                ds.Tables(0).Rows.Add(row)

                'placeholder for sql settings
                row = ds.Tables(0).NewRow
                row("dbtype") = 1
                row("provider") = "sqloledb"
                ds.Tables(0).Rows.Add(row)
            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")}

        ds.Tables.Add(table)
    End Sub

Charlotte


-----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
To: VBA
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.

Anybody?

--
John W. Colby
www.ColbyConsulting.com
_______________________________________________
dba-VB mailing list
dba-VB at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-vb
http://www.databaseadvisors.com


_______________________________________________
dba-VB mailing list
dba-VB at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-vb
http://www.databaseadvisors.com


No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 9.0.709 / Virus Database: 270.14.91/2541 - Release Date:
12/04/09 06:36:00




More information about the dba-VB mailing list