'put a error handler on error goto cnnErr dim cnn As New ADODB.Connection 'if you are using ODBC / DSN based connection use following cnn.open "dsn=dsnName;uid=username;pwd=thepassword;database=urdatabase" 'if you are using OLE DB / DSN less connection use following cnn.open "driver={SQL Server};server=urServer;uid=username;pwd=thepassword;database=urdatabase" cnnErr: msgbox "unable to connect to database"You can also check the state of the connection by state property of connection
if cnn.state=adstateClosed then msgbox "could not open connection" else ' i.e. adStateOpen 'connction is open end if