?
Solved

Need to access the Project - Settings in VS 2008?

Posted on 2009-02-12
7
Medium Priority
?
867 Views
Last Modified: 2013-11-26
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.
0
Comment
Question by:ITCSAdmin
  • 4
  • 2
7 Comments
 
LVL 12

Expert Comment

by:Munawar Hussain
ID: 23629618
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
0
 

Author Comment

by:ITCSAdmin
ID: 23629673
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?
0
 
LVL 1

Expert Comment

by:vkarumbaiah
ID: 23673290
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


0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:ITCSAdmin
ID: 23681403
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

0
 

Author Comment

by:ITCSAdmin
ID: 23820669
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!!!
0
 

Accepted Solution

by:
ITCSAdmin earned 0 total points
ID: 23823088
needo_jee & vkarumbaiah

I have found part two by watching the following video http://windowsclient.net/learn/video.aspx?v=13409 on "Datasets and Connection Strings" by Pat Tormey. Check it out, it really works.
0
 
LVL 1

Expert Comment

by:vkarumbaiah
ID: 23824635
ITCSAdmin
Yep that works too! Thanks for posting the links to the videos! they're great.
Vkarumbaiah
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question