Solved

Excel VBA connection to SQL

Posted on 2011-09-12
2
222 Views
Last Modified: 2012-08-13
Hi

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

0
Comment
Question by:murbro
2 Comments
 
LVL 17

Accepted Solution

by:
Shanmuga Sundaram earned 500 total points
Comment Utility
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.
0
 

Author Closing Comment

by:murbro
Comment Utility
thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now