CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Sep 2007
    Posts
    405

    SQL connection in the app.config file?

    After the load is connected to the variable string "connectionString", Question of the standard functions of C # can be taken out each piece as: [Server = localhost] and [Port = 5432] and ... [CommandTimeout = 10], to give them form into log form as SQL Server Management Studio 2005 from here Modifying, update, add delete, ... and after the break will be saved to the app.config file

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: SQL connection in the app.config file?

    What is your question?

  3. #3
    Join Date
    Sep 2007
    Posts
    405

    Re: SQL connection in the app.config file?

    How to change connection string in app.config dynamicaly using c#.net2.0 ?

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: SQL connection in the app.config file?

    Use more than one instance of SQLExpress. SQLExpress1, SQLExpress2, etc.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Sep 2007
    Posts
    405

    Re: SQL connection in the app.config file?

    i save connectstring warning error: The index being passed in is out of range

    Code:
    public void updateConfigFile(string con)
    {
    //updating config file
    XmlDocument XmlDoc = new XmlDocument();
    //Loading the Config file
    XmlDoc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
    foreach (XmlElement xElement in XmlDoc.DocumentElement)
    {
    if (xElement.Name == "connectionStrings")
    {
    //setting the connection string
    xElement.FirstChild.Attributes[2].Value = con; // error here
    }
    }
    //writing the connection string in config file
    XmlDoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
    }

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: SQL connection in the app.config file?

    Quote Originally Posted by dongtrien View Post
    i save connectstring warning error: The index being passed in is out of range

    Code:
    //setting the connection string
    xElement.FirstChild.Attributes[2].Value = con; // error here
    So why do you pass index 2 when 2 is out of range?
    Victor Nijegorodov

  7. #7
    Join Date
    Sep 2007
    Posts
    405

    Re: SQL connection in the app.config file?

    because the connection string have got 2 the connection string

    Also, when running the program does not understand why the folder bin\Debug\ always appear 2 files: Myprogram.exe.config (file containing an unencrypted connection string) and Myprogram.vshost.exe.config (containing the string encrypted connection), it normally only files appear Myprogram.exe.config why add another file? how can I turn down one file?
    Last edited by dongtrien; October 30th, 2014 at 09:26 PM.

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: SQL connection in the app.config file?

    Quote Originally Posted by dongtrien View Post
    because the connection string have got 2 the connection string
    Even if there are two, the index cannot be 2: only 0 and 1.
    Victor Nijegorodov

  9. #9
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: SQL connection in the app.config file?

    Quote Originally Posted by dongtrien View Post
    because the connection string have got 2 the connection string

    Also, when running the program does not understand why the folder bin\Debug\ always appear 2 files: Myprogram.exe.config (file containing an unencrypted connection string) and Myprogram.vshost.exe.config (containing the string encrypted connection), it normally only files appear Myprogram.exe.config why add another file? how can I turn down one file?
    The xxx.vshost.exe.config gets created when you debug your program from inside the Visual Studio IDE. It won't get used (or created) when running outside Visual Studio.

  10. #10
    Join Date
    Sep 2007
    Posts
    405

    Re: SQL connection in the app.config file?

    encrypt the connection string in the app.config file ? While this example was run error: Unable to find manifest signing certificate in the certificate store? and error connection string in the app.config file. thanks to bands such property protection. you see link: http://www.ardabasoglu.com/blog/encr...ation-settings

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured