Link to home
Start Free TrialLog in
Avatar of ITCSAdmin
ITCSAdminFlag for United States of America

asked on

Need to access the Project - Settings in VS 2008?

I need to get access to the Project - Settings in Visual Studio 2008 via Code, I found out how to do it in VS 2005 - GetDefaults() [In this video by Pat Tormey demonstrates how to implement settings and place resources in Visual Studio.], but VS 2008 does not have GetDefaults(). I couild not find anything for Visual Studio 2008.

So what do I use in my code and where do I place it?
Reason and Goal: I  need to be able to change the Connection string for SQL in my entire project from my site to the customers site.
Avatar of Munawar Hussain
Munawar Hussain
Flag of Pakistan image

hi, It seems for a webapplication these settings(connection) should be in webconfig file that can be edited using configurationManager from System.Configuration namespace.

and in Window forms application it should either in app.config or Application settings.

appconfig can do edited using same way configurationManager and for applicationSettings you may access via My.******* its propertiese.


not sure, if was that same that are trying to ask?


thanks
Avatar of ITCSAdmin

ASKER

I think I have part of the solution, but I have not find out any additional information to help me complete the following:
My.MySettings.Default.PLMConnectionString.

"PLMConnectionString" is the ConnectionString that I am using, but what I need is to know how to change the String after Deployment to match the customers information.
  • My current String is: "Data Source=ITCS-SQL-01; Initial Catalog=PLM; User ID=PLMAdmin; Password=*********"
  • Customers Should be: "Data Source=RPL-ADS01;Initial Catalog=PLM;User ID=PLMAdmin;Password=*********"
Also where in my project do I need to place this code to make it global?
Hi ITCSAdmin,

I tend not to use the default settings file for applications since this gets baked in to the dll once the application is compiled and the only way to change it is to recompile and redeploy the solution with the new default settings.

The better and easier way to have configurable settings for an application on a global level is to have an
 secion in your web.config (web application) or app.config (windows application)

so here are the steps
1. Add an app.config or web.config (if you don't already have one) to the startup application in your solution
2. Add an appsettings node as follows within the   tags in the config file

 
.
.
.

   

 


3. Import System.Configuration in the .vb file where you need to access the configuration
   IMPORTS System.Configuration

4. In place of ConnectionString= My.MySettings.Default.PLMConnectionString.
use  ConnectionString= ConfigurationManager.AppSettings["ConnectionString"]

5. Now you can compile and deploy your application to your customer and all you have to do is change the value of the connectionstring setting from

To


I was OK up to step 2, but step 3 and beyond I am lost. Would you please turn the lighth on for me. Remember I am developing in VS 2008/VB9, am using SQL 2005 and I am a beginner. This is my first project, and it is a large and complex project as I now see it and have been told. Though I have a customer that needs this application and yet I want to "Do It Right!"

Attached is the APP.Config code for this Application:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="ConnectionString" value="Data Source=ITCS-SQL-01; Initial Catalog=PLM; User ID=PLMAdmin; Password=*********"/>
  </appSettings>
 
    <configSections>
    </configSections>
    <connectionStrings>
        <add name="Lighthouse.My.MySettings.PLMConnectionStringDev" connectionString="Data Source=ITCS-SQL-01;Initial Catalog=PLM;User ID=PLMAdmin;Password=PLMA@dm1n"
            providerName="System.Data.SqlClient" />
        <add name="Lighthouse.My.MySettings.PLMConnectionStringDeploy" connectionString="Data Source=RPL-ADS01;Initial Catalog=PLM;User ID=PLMAdmin;Password=PLMA@dm1n" />
    </connectionStrings>
    <system.diagnostics>
        <sources>
            <!-- This section defines the logging configuration for My.Application.Log -->
            <source name="DefaultSource" switchName="DefaultSwitch">
                <listeners>
                    <add name="FileLog"/>
                    <!-- Uncomment the below section to write to the Application Event Log -->
                    <add name="EventLog"/>
                </listeners>
            </source>
        </sources>
        <switches>
            <add name="DefaultSwitch" value="Information" />
        </switches>
        <sharedListeners>
            <add name="FileLog"
                 type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
                 initializeData="FileLogWriter"/>
            <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
            <add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="Lighthouse"/> 
        </sharedListeners>
    </system.diagnostics>
</configuration>

Open in new window

needo_jee & vkarumbaiah

I found part of my question and would like to update you on where I got the information. There is a big difference between Visual Studio 2005 and 2008. This is one of them. To deploy in VS 2005, you would just from you toolbar, change it from Debug to Deploy, but in VS 2008 you now have to due the following:

Watch the following Video http://windowsclient.net/learn/video.aspx?v=14636

This is the first part, Now the second is I need to be able to switch from SQL 2005 Standard (Development) to either SQL 2005 Express or SQL 2008 Express (Deployment) ConnectionString or do I have to change my project to ONLY use either SQL Standard or SQL Express for the entire project.

Also, this solution needs to work across the entire project, multiple Tables, multiple Forms, Multiple DataSets, etc..

Have any suggestions or thoughts?



REMEMBER I am using Visual Studio 2008 Professional!!!
ASKER CERTIFIED SOLUTION
Avatar of ITCSAdmin
ITCSAdmin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ITCSAdmin
Yep that works too! Thanks for posting the links to the videos! they're great.
Vkarumbaiah