using FirebirdSql.Data.FirebirdClient; using System; using System.Data; using System.IO; using System.Configuration; using System.Windows.Forms; using System.Xml; public class Class_Connection { private FbConnection Fb_Connection; public string Fb_ConnectionTXT() { StreamReader objReader = new StreamReader("\\FirebirdCN\\Firebird.txt"); String ConnectionString; ConnectionString = ""; ConnectionString = objReader.ReadLine(); return ConnectionString; } public String Fb_ConnectionXML() { XmlDocument Xml; XmlNodeList NodeList; String ConnectionString = ""; Xml = new XmlDocument(); Xml.Load(Application.StartupPath + "\\FirebirdCN\\Firebird.xml"); NodeList = Xml.SelectNodes("/FirebirCN"); foreach (XmlNode Node in NodeList) { ConnectionString = ConnectionString + Node.ChildNodes.Item(0).Name + "=" + Node.ChildNodes.Item(0).InnerText + "; "; ConnectionString = ConnectionString + Node.ChildNodes.Item(1).Name + "=" + Node.ChildNodes.Item(1).InnerText + "; "; ConnectionString = ConnectionString + Node.ChildNodes.Item(2).Name + "=" + Node.ChildNodes.Item(2).InnerText + "; "; ConnectionString = ConnectionString + Node.ChildNodes.Item(3).Name + "=" + Node.ChildNodes.Item(3).InnerText + "; "; ConnectionString = ConnectionString + Node.ChildNodes.Item(4).Name + "=" + Node.ChildNodes.Item(4).InnerText + "; "; ConnectionString = ConnectionString + Node.ChildNodes.Item(5).Name + "=" + Node.ChildNodes.Item(5).InnerText + "; "; ConnectionString = ConnectionString + Node.ChildNodes.Item(6).Name + "=" + Node.ChildNodes.Item(6).InnerText + "; "; ConnectionString = ConnectionString + Node.ChildNodes.Item(7).Name + "=" + Node.ChildNodes.Item(7).InnerText; } return ConnectionString; } public void Fb_Open() { try { Fb_Connection = new FbConnection(); Fb_Connection.ConnectionString = Fb_ConnectionXML(); Fb_Connection.Open(); } catch (InvalidCastException e) { MessageBox.Show("Unable to establish the Connection to the server"); } } public void Fb_Close() { Fb_Connection.Close(); } public void Fb_Execute(String SQL) { try { Fb_Open(); FbCommand cmd = new FbCommand(SQL, Fb_Connection); cmd.ExecuteNonQuery(); Fb_Close(); } catch (InvalidCastException e) { MessageBox.Show("Unable to establish the Connection to the server"); } } public DataTable Fb_DataTable(String SQL) { DataTable dt = new DataTable(); try { Fb_Open(); FbDataAdapter da = new FbDataAdapter(SQL, Fb_Connection); da.Fill(dt); Fb_Close(); } catch (InvalidCastException e) { MessageBox.Show("Unable to establish the Connection to the server"); } return dt; } public DataSet Fb_DataSet(String SQL) { DataSet dt = new DataSet(); try { Fb_Open(); FbDataAdapter da = new FbDataAdapter(SQL, Fb_Connection); da.Fill(dt, "Table"); Fb_Close(); } catch (InvalidCastException e) { MessageBox.Show("Unable to establish the Connection to the server"); } return dt; } }
El contenido del alchivo TXT
ServerType=0; User=SYSDBA; Password=masterkey; database=127.0.0.1:C:\LIMPIA.FDB; charset=UTF8 User=SYSDBA; Password=masterkey; DataSource=localhost; Database=C:\LIMPIA.FDB; Charset=UTF8; Port=; Pooling=true; ServerType=0
El Contenido del archivo XML
<?xml version="1.0" encoding="UTF-8"?> <FirebirCN> <User>TheUser</User> <Password>ThePassword</Password> <Server>TheServer</Server> <Database>C:\Database.FDB</Database> <Charset>UTF8</Charset> <Port> </Port> <Pooling>false</Pooling> <ServerType>0</ServerType> </FirebirCN>
Añadir referencias a las siguientes librerías
Download: FirebirdSql.Data.FirebirdClient.dll
Download: FirebirdDataAccess.Zhero.dll