How To Switch Between Two Connection String Constants

Larry Haydn

Board Regular
Joined
Jul 18, 2019
Messages
207
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

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
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.
 
Upvote 0
Solution

Forum statistics

Threads
1,213,560
Messages
6,114,306
Members
448,564
Latest member
ED38

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
Back
Top