jwcolby
jwcolby at colbyconsulting.com
Fri Dec 4 07:56:15 CST 2009
Charlotte, My question really is how do I get at the settings area of the project, and why would I not use that instead of this xml thing of yours? At least in this specific case, I am writing code for myself, not distribution. John W. Colby www.ColbyConsulting.com Charlotte Foust wrote: > 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 > >