How To Switch Between Two Connection String Constants

Larry Haydn

Board Regular
Joined
Jul 18, 2019
Messages
138
Office Version
  1. 365
Platform
  1. Windows
I develop Excel VBA application with my own SQL Server, and installs at client's premises which uses their SQL Server.
Because of this, I have to create 2 separate connection strings.
When I am using my own server, I deactivate the Client CN.
When I install at customer site, I deactivate my own CN and use the client CN.

Is there a way to switch between these two connection strings, instead of commenting them out?


VBA Code:
Public Const SQLConnStr As String = "Provider=SQLOLEDB;" & _
                                    "Data Source=[B]MyDBname[/B];" & _
                                    "user id=[B]me\username[/B];" & _
                                    "password=[B]MyPwd[/B];" & _
                                    "Initial Catalog=PRODUCTION;" & _
                                    "Integrated Security=SSPI;"
                                    
[COLOR=rgb(65, 168, 95)]'Public Const SQLConnStr As String = "Provider=SQLOLEDB;" & _
                                    "Data Source=[B]ClientDBname[/B];" & _
                                    "user id=[B]client\username[/B];" & _
                                    "password=[B]ClientPwd[/B];" & _
                                    "Initial Catalog=PRODUCTION;" & _
                                    "Integrated Security=SSPI;"[/COLOR]
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

RayFrye

Board Regular
Joined
Jan 31, 2005
Messages
122
Office Version
  1. 365
  2. 2019
I check the computer name to determine which PC the software is running on and use that to determine the connection sting for the current PC.
 

Forum statistics

Threads
1,136,969
Messages
5,678,893
Members
419,787
Latest member
juanam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top