We help IT Professionals succeed at work.

How do you change the ConnectionString for Entire Project?

Medium Priority
807 Views
Last Modified: 2013-11-26
How do I change the SQL ConnectionString when I am developing this appliaction in my Office and yet be able to deploy it at my customers location?

Below is the current code that was suppose to allow me to automatically switch between installed locations, but it is NOT. Is there something that I did or did not do when publishing the application or during the installation of the appliaction?
Module module_Lighthouse
    Private Function GetData() As DataTable
 
        Dim connectionString As String = String.Empty
 
#If Debug = True Then
        connectionString = My.Settings.PLMConnectionStringDev     'Development connection string
#Else
        connectionString = My.Settings.PLMConnectionStringDeploy   'Deployment connection string
#End If
 
        Dim SQL As String = "SELECT * FROM myTable"
 
        Dim table As New DataTable()
 
        Dim adapter As New SqlClient.SqlDataAdapter(SQL, connectionString)
        adapter.Fill(table)
 
        adapter.Dispose()
 
        Return table
 
    End Function
 
End Module

Open in new window

Comment
Watch Question

Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
That should work fine !
Are you using that variable "connectionString " in more places ?
Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
If you do a simple test and use F5 and then CTRL+F5 to test it you see that works fine
Public Class Form1
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        MessageBox.Show(Information)
 
    End Sub
 
End Class
 
 
Module abc
 
    Public Function Information() As String
        Dim result As String = String.Empty
 
#If Debug = True Then
        result = "debug"
#Else
        result = "release"
#End If
 
        Return result
    End Function
 
End Module

Open in new window

Commented:
compile the application in release mode , default is debug mode
on your toolbar there should be a dropdown box with options debug and release. select release there and build the application and execute exe from release folder.

Author

Commented:
jpaulino:

Sorry that it took so long for me to get back tp you, but I have ben busy with cleints and am trying to understand and then test what you sent me.

To answer your first response, I am not sure because I have not written any code to use the "connectionstring".

The following is a basic process that I am using to make my current appliaction:
 I have used the process where you create your Windows Form, create your DataSet, Select the table in your Dataset, Set it to "Details" and drag and drop table onto form, arrange fields and labels, place the BindingNavigator on the bottom, Build, Publish and then deploy. It is when I deployed the application that I could NOT get the appliaction to connect to the clients SQL Server from there workstation.
The code that I have currently installed was given to me as a solution, but did not work. This is my very first application that I have ever built with a dependencies to a SQL Database. Otherwise I am very new, some VB6 work, But with VB9, ONLY Since December of 2008. I have taken on a very big project as my first project to develope.
Please feel free to ask questions, I am very glad to respond back.

Commented:
see the attached image, and I marked some area in  red colored rectangle. you will find similar area on your toolbar. change the option to release there before building and deploying your application.

BuildModeChange.JPG

Author

Commented:
The default toolbar for Visual Studio 2008 does NOT have that toolbar active. which toolbar do I need to activate?  View - Toolbars - ?

Commented:
it should be in view->toolbars->standard.
I am still working on visual studio 2005. if it is not there in standard toolbar in the try to find in the build menu->configuration manager or something like that. in that you can change the active configuration to release mode.

Commented:
check this link on how to change mode,
http://msdn.microsoft.com/en-us/library/wx0123s5.aspx

Author

Commented:
appari

I have read the link and for some reason my Visual Studio 2008 Professional does NOT give me that option on the page that they say it is. I also have checked every where and still have NOT fould that option.

Should I contact Micorsoft Technical Support or do you have another suggestion?

Commented:
may be missing something ,
can you take the screenshot and post it here
Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
Sorry for the delay ... busy week :)
One question: do you have used wizards to fill comboboxes, datagridviews, bindingsources, etc ? Because that way you have to change the connection of that binding.
 

Commented:

usually i never use wizards, code it all myself. still i think its possible to change the connection details in code even for the controls generated using wizards.
Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
I also don't use wizards but the are very usefull for those how are starting.
And it's possible to change the connection details for them.

Author

Commented:
jpaulino:

See my screen shot of Visual Studio 2008 Professional
Visual-Studio-2008---Project---S.JPG

Author

Commented:
jpaulino

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!!!
jpaulino

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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
Sorry it's being very difficult to read all the email and reply to all :(
Glad you have solved your problem and sorry once again!
jpaulino
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.