Excel VBA connection to SQL


I use the connection string in my code below to manipulate an online SQL database from Excel
I want to include a text box or other control that stays green while the databse can be connected to and turns red when it can't be connected to. What sort of VBA code would I use
to do this
Public Sub oAppend(ByVal oDate As Date, ByVal oText As String, ByVal oNumber As Single)
    Dim oSQL As String
    On Error GoTo EH
    Set con = New ADODB.Connection
    con.Open "Provider=SQLOLEDB;Data Source=196.11.247,1884;Network Library=DBMSSOCN;Initial Catalog=test;User ID=llllk3;Password=4lllgg;"

    Set cmd = New ADODB.Command

Open in new window

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
Shanmuga SundaramConnect With a Mentor Director of Software EngineeringCommented:
try using a timer object and that timerobject should check for connection status. if the connection state is 1 then you can make it as green and if the state is 0 then make it as red.
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.