BUG: RegisterDatabase Fails After ODBC Version 2.x InstalledLast reviewed: February 26, 1996Article ID: Q126940 |
The information in this article applies to:
- Professional Edition of Microsoft Visual Basic for Windows, version 3.0
SYMPTOMSThe RegisterDatabase function fails and returns error 3146 "ODBC call failed" after ODBC version 2.x has been installed.
CAUSEThe ODBC API function SQLConfigDataSource() was not correctly implemented in ODBC version 1.0. The RegisterDatabase function in Visual Basic version 3.0 was designed to use the ODBC version 1.0 implementation of SQLConfigDataSource(). SQLConfigDataSource() is now implemented correctly in ODBC version 2.x. If ODBC version 2.x has been installed you will find that an application that uses RegisterDatabase will fail with the error 3146 "ODBC call failed." Visual Basic exhibits this problem when using RegisterDatabase because it was based on the original implementation of SQLConfigDataSource(). The underlying function that RegisterDatabase ultimately calls has been changed and Visual Basic's RegisterDatabase function will now generate the error if the ODBC version 2.x DLLs are installed.
WORKAROUNDYou can code directly to the ODBC API and register your DSN with SQLConfigDataSource(). Below is a code sample that will replace the functionality of Visual Basic's RegisterDatabase function. It first tries to use RegisterDatabase, if that fails, it uses the ODBC API function SQLConfigDataSource. You can call this function instead of calling RegisterDatabase.
Step-by-Step Example
If Err = 3146 Then ' ODBC Call Failed. Dim temp As String Dim spot As Integer While InStr(attributes, Chr(13)) ' Replace Carriage returns spot = InStr(attributes, Chr(13)) ' with nulls. Mid(attributes, spot, 1) = Chr(0) Wend attributes = attributes & Chr(0) & Chr(0) ' End of attribute section. temp = "DSN=" & dsn & Chr(0) & attributes ret = SQLConfigDataSource(0, ODBC_ADD_DSN, driver, temp) ' ret is equal to 1 on success and 0 if there is an error. If ret <> 1 Then MsgBox "SQLConfigDataSource call failed" Else MsgBox " SQLConfigDataSource call succeeded!" End If End If Exit Sub End Sub RegisterODBCDatabase "Pubs", "SqlServer", "True, Att$ As a result, you will receive a message stating the new datasource was added successfully.
STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.
MORE INFORMATION
Steps to Reproduce Problem
REFERENCES"Microsoft ODBC 2.0 Programmer's Guide and SDK Guide" Chapter 24.
|
Additional reference words: 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |