[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 796
  • Last Modified:

How do you change the ConnectionString for Entire Project?

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

0
ITCSAdmin
Asked:
ITCSAdmin
  • 6
  • 6
  • 5
1 Solution
 
jpaulinoCommented:
That should work fine !
Are you using that variable "connectionString " in more places ?
0
 
jpaulinoCommented:
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

0
 
appariCommented:
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.
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
ITCSAdminAuthor 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.
0
 
appariCommented:
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
0
 
ITCSAdminAuthor Commented:
The default toolbar for Visual Studio 2008 does NOT have that toolbar active. which toolbar do I need to activate?  View - Toolbars - ?
0
 
appariCommented:
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.
0
 
appariCommented:
check this link on how to change mode,
http://msdn.microsoft.com/en-us/library/wx0123s5.aspx
0
 
ITCSAdminAuthor 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?
0
 
appariCommented:
may be missing something ,
can you take the screenshot and post it here
0
 
jpaulinoCommented:
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.
 
0
 
appariCommented:

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.
0
 
jpaulinoCommented:
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.
0
 
ITCSAdminAuthor Commented:
jpaulino:

See my screen shot of Visual Studio 2008 Professional
Visual-Studio-2008---Project---S.JPG
0
 
ITCSAdminAuthor 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!!!
0
 
ITCSAdminAuthor Commented:
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.
0
 
jpaulinoCommented:
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
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now