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;
                }
            }

Thanks Abellazm let me check this

What assembly should i include to read Domain ?

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

Thanks Abel you are a gr8 help thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.