none
How To use the Settings from the main project in all the other (.dll) Projects RRS feed

  • Question

  • I have a main project through which I login with a username and password, and the connection string to SQL.

    It is saved in the settings of the Main Project.

    All my other projects are saved as .dll and each project has their own settings, but they need the connection string that is saved in the Main project.

    How can I call the connection string (saved in the Main Project settings) easily in all the other projects?

    Look forward to your advice.

    thanks

    Sunday, November 18, 2018 9:01 PM

Answers

  • Hello,

    Settings and ConnectionString are stored in My Namespace which is accessible only in the application that created them. 

    Your options are to a) read the connection string from the other app's app.config file or consider a different approach such as this one which is shown for SQL-Server but could be used for MS-Access, MySql, Oracle etc. It may not be an exact match but offers an alternative.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by MosheS Singer Monday, November 19, 2018 7:41 PM
    Sunday, November 18, 2018 10:37 PM
    Moderator

All replies

  • Hello,

    Settings and ConnectionString are stored in My Namespace which is accessible only in the application that created them. 

    Your options are to a) read the connection string from the other app's app.config file or consider a different approach such as this one which is shown for SQL-Server but could be used for MS-Access, MySql, Oracle etc. It may not be an exact match but offers an alternative.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by MosheS Singer Monday, November 19, 2018 7:41 PM
    Sunday, November 18, 2018 10:37 PM
    Moderator
  • .NET looks for all configuration information in the root project's app.config file. Any projects bellow the root project must copy the app.config content of the classlib project to the app.config of the root project so that .NET can find the configuration information at program runtime.The project that creates the programname.exe file is the root project, which should have an app.config in the project.

    To get the connectionstring information out of the root project's app.config, one uses the ConfigurationManager function.

    https://docs.microsoft.com/en-us/dotnet/api/system.configuration.configurationmanager.connectionstrings?view=netframework-4.7.2

    VB example.....

    https://stackoverflow.com/questions/5671112/correctly-declaring-configurationmanager-when-connecting-to-database

    Note: Upon the successful build of the root project that creates a programname.exe. Visual Studio creates a runtime config file named programname.exe.config that sits in the Bin folder along with the programname.exe file, which holds the content of the app.config that was copied to the runtime config file. You deploy the programname.exe file to a location, then the programname.exe.config file must be deployed to the same location so that .NET can find the configuration information.

     

    Monday, November 19, 2018 12:36 AM