2
Contributors
7
Replies
9
Views
6 Years
Discussion Span
Last Post by bahed121
1

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 by abelLazm: n/a

0

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

0

It is still not working giving error at

connection_string(xmlrdr.GetAttribute(1));
0

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 by abelLazm: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.