473,385 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How To: Suppress ODBC Connection Dialog?

I have an Access front end connecting to an SQL Server back-end. When the
application opens, I run a small test to determine if the SQL Server is
available. If it is not, I have code to trap the 'On Error' event.
Unfortunately, a 'SQL Server Login' dialog appears before my 'On Error' code
has a chance to run. Does anybody know how to prevent the dialog from
appearing? Suppressing warnings (DoCmd.SetWarnings FALSE) has no effect.

Thanks,
Scott
Nov 13 '05 #1
5 13490
Scott A. Jones wrote:
I have an Access front end connecting to an SQL Server back-end. When the
application opens, I run a small test to determine if the SQL Server is
available. If it is not, I have code to trap the 'On Error' event.
Unfortunately, a 'SQL Server Login' dialog appears before my 'On Error' code
has a chance to run. Does anybody know how to prevent the dialog from
appearing? Suppressing warnings (DoCmd.SetWarnings FALSE) has no effect.


I have the same problem trying to open a database in DAO, no matter what
options I put into OpenDatabase() it will still prompt if the password
is wrong, etc. So I pop in a little bit of ADO...

Function CanOpenSQLDbLB(pstrServer As String, pstrDb As String, pstrUser
As String, pstrPassword As String, Optional pfReportError As Boolean =
True) As Boolean
' Error Trapped: 04/02/2003 09:50:00 Admin
On Error GoTo CanOpenSQLDbLB_Err
' try late binding

Dim objConn As Object
Dim strConn As String
Dim strError As String, lngErr As Long
Const cstrSQLErr = "[Microsoft][ODBC SQL Server Driver][SQL Server]"

Set objConn = CreateObject("ADODB.Connection")

strConn = strConn & "DRIVER=SQL Server"
strConn = strConn & ";SERVER=" & pstrServer
strConn = strConn & ";APP=" & Application.Name
strConn = strConn & ";WSID=AWorkstation"
strConn = strConn & ";DATABASE=" & pstrDb

objConn.Open strConn, pstrUser, pstrPassword

' Q'PLAGH
CanOpenSQLDbLB = True

CanOpenSQLDbLB_Exit:
On Error Resume Next
objConn.Close
Set objConn = Nothing
Exit Function
CanOpenSQLDbLB_Err:
lngErr = Err.Number
strError = Err.Description
'MsgBox strError
If InStr(1, strError, cstrSQLErr) Then
strError = "Error reported by server" & vbCr & vbCr &
Replace(strError, cstrSQLErr, "")
End If
'Debug.Print strError
Select Case lngErr
Case Else
If pfReportError Then
MsgBox strError, 16, "Error #" & Err & " Attempting to
open server database"
End If
End Select
Resume CanOpenSQLDbLB_Exit

End Function
--

\\\\\\
\\ \\ Windows is searching
\ \ For your sig.
\ \ Please Wait.
\__\

Nov 13 '05 #2
Try linking to the SQL table with an ODBC object, and when you do, click
'Save Password'. That way you wont be prompted for the password, and you
can use the table as an access table.

HTH

Alec Christie
alec_e_christie(at)hotmail(dot)com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #3

On 23-Sep-2004, Trevor Best <nospam@localhost> wrote:
Function CanOpenSQLDbLB(pstrServer As String, pstrDb As String, pstrUser
As String, pstrPassword As String, Optional pfReportError As Boolean =
True) As Boolean
' Error Trapped: 04/02/2003 09:50:00 Admin
On Error GoTo CanOpenSQLDbLB_Err
' try late binding

Dim objConn As Object
Dim strConn As String
Dim strError As String, lngErr As Long
Const cstrSQLErr = "[Microsoft][ODBC SQL Server Driver][SQL Server]"

Set objConn = CreateObject("ADODB.Connection")

strConn = strConn & "DRIVER=SQL Server"
strConn = strConn & ";SERVER=" & pstrServer
strConn = strConn & ";APP=" & Application.Name
strConn = strConn & ";WSID=AWorkstation"
strConn = strConn & ";DATABASE=" & pstrDb

objConn.Open strConn, pstrUser, pstrPassword

' Q'PLAGH
CanOpenSQLDbLB = True

CanOpenSQLDbLB_Exit:
On Error Resume Next
objConn.Close
Set objConn = Nothing
Exit Function
CanOpenSQLDbLB_Err:
lngErr = Err.Number
strError = Err.Description
'MsgBox strError
If InStr(1, strError, cstrSQLErr) Then
strError = "Error reported by server" & vbCr & vbCr &
Replace(strError, cstrSQLErr, "")
End If
'Debug.Print strError
Select Case lngErr
Case Else
If pfReportError Then
MsgBox strError, 16, "Error #" & Err & " Attempting to
open server database"
End If
End Select
Resume CanOpenSQLDbLB_Exit

End Function


Trevor,

Thanks for the reply. Your code worked great! Problem solved!!

Question: What is the purpose of the pfReportError boolean? I couldn't
figure it out from reading your code.

Thanks,
Scott
Nov 13 '05 #4
Scott A. Jones wrote:
On 23-Sep-2004, Trevor Best <nospam@localhost> wrote:

Function CanOpenSQLDbLB(pstrServer As String, pstrDb As String, pstrUser
As String, pstrPassword As String, Optional pfReportError As Boolean =
True) As Boolean
' Error Trapped: 04/02/2003 09:50:00 Admin
On Error GoTo CanOpenSQLDbLB_Err
' try late binding

Dim objConn As Object
Dim strConn As String
Dim strError As String, lngErr As Long
Const cstrSQLErr = "[Microsoft][ODBC SQL Server Driver][SQL Server]"

Set objConn = CreateObject("ADODB.Connection")

strConn = strConn & "DRIVER=SQL Server"
strConn = strConn & ";SERVER=" & pstrServer
strConn = strConn & ";APP=" & Application.Name
strConn = strConn & ";WSID=AWorkstation"
strConn = strConn & ";DATABASE=" & pstrDb

objConn.Open strConn, pstrUser, pstrPassword

' Q'PLAGH
CanOpenSQLDbLB = True

CanOpenSQLDbLB_Exit:
On Error Resume Next
objConn.Close
Set objConn = Nothing
Exit Function
CanOpenSQLDbLB_Err:
lngErr = Err.Number
strError = Err.Description
'MsgBox strError
If InStr(1, strError, cstrSQLErr) Then
strError = "Error reported by server" & vbCr & vbCr &
Replace(strError, cstrSQLErr, "")
End If
'Debug.Print strError
Select Case lngErr
Case Else
If pfReportError Then
MsgBox strError, 16, "Error #" & Err & " Attempting to
open server database"
End If
End Select
Resume CanOpenSQLDbLB_Exit

End Function

Trevor,

Thanks for the reply. Your code worked great! Problem solved!!

Question: What is the purpose of the pfReportError boolean? I couldn't
figure it out from reading your code.

Thanks,
Scott


If true, a MsgBox will appear with the error message, if false then the
function quietly exits and returns 0 (IOW cannot connect).
--

\\\\\\
\\ \\ Windows is searching
\ \ For your sig.
\ \ Please Wait.
\__\

Nov 13 '05 #5
Do it in reverse order: Get user name and password and then establish
connection.
Insert the ODBC connection string (with user name and password) in a SQL
sentence. This wil avoid the popup when you use the linked tables:

strOdbcCon="ODBC" _
& ";DRIVER=SQL Server" -
& ";SERVER=YourServer" _
& ";DATABASE=YourDatabase" _
& ";uid=" & strUserName _
& ";pwd=" & strPassword

strSQL="SELECT * FROM [" & strOdbcCon & "].OneTable WHERE FALSE"
set db=currentdb
set rs=dbs.openrecordset(strSQL,dbOpenNapshot)

It works.

"Scott A. Jones" <sa*****@gmx.net> escribió en el mensaje
news:ci*********@enews1.newsguy.com...
I have an Access front end connecting to an SQL Server back-end. When the
application opens, I run a small test to determine if the SQL Server is
available. If it is not, I have code to trap the 'On Error' event.
Unfortunately, a 'SQL Server Login' dialog appears before my 'On Error' code has a chance to run. Does anybody know how to prevent the dialog from
appearing? Suppressing warnings (DoCmd.SetWarnings FALSE) has no effect.

Thanks,
Scott

Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dr. Indera | last post by:
hi, this may be a bit long, but i want to make sure i explain my questions. (aka, not real experienced with visual studio.net) i'm using visual studio.net 2003 (visual basic.net and crystal...
11
by: DJJ | last post by:
I am using the MySQL ODBC 3.51 driver to link three relatively small MySQL tables to a Microsoft Access 2003 database. I am finding that the data from the MySQL tables takes a hell of a long time...
0
by: Ragtimer | last post by:
I've been trying to build a DAO.QueryDef.Connect string, building it from a user ID and password string obtained previously by a log-in dialog box, using it to log in to an Oracle database through...
3
by: vitagoni | last post by:
Hi there, I'm new in C#. But not in programming. I used to call odbc32.dll before, so I was working with ODBC API commands. Can you advice a way whichis better for using in VC2003 C#? I'm trying...
1
by: Jozsef Bekes | last post by:
Hello All, is it possible to make the ODBC connection dialog box appear when connecting to a db using the classes in the System.Data.Odbc namespace? I could not find a way except for invoking the...
0
by: Henry C. Wu | last post by:
I tried the link: http://support.microsoft.com/?id=193128 to prompt the ODBC Data Source dialog box, but the syntax ".Properties("Prompt") = adPromptAlways" rendered an error stating that it is...
2
by: polpe | last post by:
Hello, i have a filemaker server 5.5 with some shared files. I don't understand how use ODBC with these files to import a database in Access. Can anyone help me? Polpe from Italy
3
by: nark | last post by:
I just downloaded ODBC drivers from the mySQL web site but whenever I try to create a DSN I get a system 1157 error The driver does show up ok in the windows control panel I cant find any...
9
by: Bob Sanderson | last post by:
I'm trying to export a table to an ODBC database using a VBA subroutine. I have tested the ODBC setup manually and it works fine but when I try to do it with VBA, I get a "connection failed" error....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.