Can any one tell me how to read connection string from XML file ??

Thanks in advance for you help

add the xml file and .dtd file in ur debug folder and add following code in where you want to extract connection string (Supposing your xml file has connection string as the first attribute )

XmlReader xmlrdr;
            XmlReaderSettings readerSetting = new XmlReaderSettings();
            readerSetting.ProhibitDtd = false;

            if (File.Exists(Application.StartupPath.ToString() + "\\FileName.xml"))
            {
                xmlrdr = XmlReader.Create(Application.StartupPath.ToString() + "\\FileName.xml", readerSetting);
            }
            else
            {
                Domain domain = Domain.GetCurrentDomain();
                DomainController dc = domain.PdcRoleOwner;
                xmlrdr = XmlReader.Create("\\\\" + dc.Name.Split('.').GetValue(0).ToString() + "\\FileName$\\FileName.xml", readerSetting);
            }

            while (xmlrdr.Read())
            {
                xmlrdr.MoveToElement();
                if (xmlrdr.NodeType == XmlNodeType.Element && xmlrdr.Name == "connection")
                {
                    if (xmlrdr.HasAttributes)
                    {
                        xmlrdr.MoveToFirstAttribute();
                        while (xmlrdr.MoveToNextAttribute())
                        {
                          String Connection_string = xmlrdr.GetAttribute(1);
                        }
                    }
                    break;
                }
            }

Edited 5 Years Ago by abelLazm: n/a

using System.DirectoryServices.ActiveDirectory; add this line this includes in the system.DirectoryServices dll

It is still not working giving error at

connection_string(xmlrdr.GetAttribute(1));

Sorry my fault that was my function where i create connection now you can check modified code i have edited the post... Pass this connection string where ever you want to create the connection

Edited 5 Years Ago by abelLazm: n/a

This question has already been answered. Start a new discussion instead.