tags:

views:

183

answers:

1

During the design-time I set the following properties of the ADO Control:

-ConnectionString -CommandType -RecordSource

At the same time, I set the following properties of the Data Grid Control:

-DataSource

My problem comes when I deploy this application in Production Environment. My Production SQL Server has different UID/PWD.

So, how do I set the above properties during run-time?

+1  A: 

IT's not too difficult. You will have to ask for, or store the user name and password for your production server and add those to the connection string. I typically use a connection string with placeholders that I will use the VB Replace function to dynamically insert the user id and password into the connection string before I assign it to the connection object.

For example:

Private Const SQL_CONNECTION_STRING = "Provider=sqloledb;Data Source=%SERVER%;Database=%DataBase%;User ID=%UserID%;Password=%Password%"

Public Sub OpenConnection(ByVal Server as String, ByVal Database as String, ByVal UserId as String, ByVal Password as String)
   strConn = SQL_CONNECTION_STRING
   strConn = Replace$(strConn, "%SERVER%", Server, , , vbTextCompare)
   strConn = Replace$(strConn, "%Database%", Database, , , vbTextCompare)
   strConn = Replace$(strConn, "%UserID%", UserId, , , vbTextCompare)
   strConn = Replace$(strConn, "%Password%", Password, , , vbTextCompare)
   ...
Beaner