VB2VB.NET: INI file or XML?
In VB programmers offten keep database connection parameter in a INI file, it looks like as blow
[database]
Driver={SQL Server}
Server=.
uid=sa
pwd=
database=myDB
do VB.NET programmers use it also? or keep them in a XML file? which one are most recommended way?does anybody have a sample? :afrog:
Re: VB2VB.NET: INI file or XML?
The XML file is the preferred way, replacing the registry and ini files both. ;)
You can find some examples of using XML files in the download from MS in the 101 .NET tutorials at the top of the VB.NET forum or
do a quick search in the VB.NET Forum. ;)
Re: VB2VB.NET: INI file or XML?
VS 2005 has made it even easier to store program settings, but 2003 is part way there. You can create your own XML files, or you can use dynamic properties and the app's config file. If you have created your database Connection object in the designer, a mechanism already exists, via DynamicProperties in the Properties window, to have the connection string stored in the config file, which will be created for you and added to your project. You then simply have to distribute that config file with your app and edit the appropriate line(s) using Notepad. The connection string is picked up automatically every time your app starts with no extra code needed. With dynamic properties, I think you could also provide a way for the user to change the data source through your app, then have that new value saved to the config file when the app exits. I haven't really used them but I think all controls can set Dynamic Properties in a similar way. You can also create your own custom sections in the config file and read them using the System.Configuration namespace. Be aware, though, that there is no easy way to edit the config file programmatically.