I am developing an c# application in which I need to fetch data from oracle database server. In my application I do not want to make a hard coded connection string because sometimes we have to connect it with different DB (for testing purpose it has same schema).
For this I have a plan that I create an xml file and a new form(with admin rights) using this form I update/insert database credentials in xml file or use app.config, but the problem is i don't have any idea how to read and write xml file in predefined manner (in same manner as a connection string should be).
Can you please help me out for creating new xml file or have any batter idea?
how about this code?
public static string ClientName, DbType, ConnectionString;
static DB()
{
try
{
DataTable Dt = new DataTable("Settings");
DataColumn Client = new DataColumn("Client", typeof(string));
DataColumn DataBaseType = new DataColumn("DataBaseType", typeof(string));
DataColumn ConString = new DataColumn("ConnectionString", typeof(string));
Dt.Columns.Add(Client);
Dt.Columns.Add(DataBaseType);
Dt.Columns.Add(ConString);
Dt.ReadXml(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Settings.xml");
DB.ClientName = Dt.Rows[0]["Client"].ToString();
DB.DbType = Dt.Rows[0]["DataBaseType"].ToString();
DB.Port = Dt.Rows[0]["Port"].ToString();
DB.ConnectionString = Dt.Rows[0]["ConnectionString"].ToString();
}
catch(Exception ex)
{
// Exception message
}
and xml file code is
<?xml version="1.0" standalone="yes"?>
<DocumentElement>
<Settings>
<Client>DSCL</Client>
<DataBaseType>ORACLE</DataBaseType>
<ConnectionString>providerName=system.data.oracleclient;User ID=****;password=****;Data Source=*****;Persist Security Info=True;Provider=OraOLEDB.Oracle;</ConnectionString>
</Settings>
</DocumentElement>