473,703 Members | 2,245 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ODBC connection failed

Hi All,

I am currently trying to link in Access 97 to a table in a MSSQL 7
server. Initially the link is fine, however, when I close the access
database and re-open it from the same network lacation on a different
machine, it tells me that the ODBC connection to 'SQL Server Name'
failed.

How can I create the linked table permenant no matter what machine the
networked database is opened on?

TIA

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 #1
5 40404
When you copy the application to another workstation and the ODBC link
doesn't work, most likely the other workstation doesn't have the DSN to
your sql server set up.

Here is some code that automatically creates a System DSN for Sql Server
on an MS Windows workstation. You can place this routine in a standard
module and call it from a startup form in the Form_Load event.

'************** *************** *************** ************
Private Const REG_SZ = 1
Private Const HKEY_LOCAL_MACH INE = &H80000002

Private Declare Function RegCreateKey Lib "advapi32.d ll" _
Alias "RegCreateK eyA" (ByVal hKey As Long, _
ByVal lpSubKey As String, phkResult As Long) As Long

Private Declare Function RegSetValueEx Lib "advapi32.d ll" Alias
"RegSetValueExA " (ByVal hKey As Long, ByVal _
lpValueName As String, ByVal Reserved As Long, _
ByVal dwType As Long, lpData As Any, ByVal _
cbData As Long) As Long

Private Declare Function RegCloseKey Lib "advapi32.d ll" _
(ByVal hKey As Long) As Long
Sub createSystemODB Cdsn()
'Microsoft Knowledge Base Article - 184608
Dim DataSourceName As String
Dim DatabaseName As String
Dim Description As String
Dim DriverPath As String
Dim DriverName As String
Dim LastUser As String
Dim Regional As String
Dim Server As String
Dim lResult As Long
Dim hKeyHandle As Long

'Specify the DSN parameters.

DataSourceName = Name of your DSN
DatabaseName = Name of the database in Sql Server
Description = simple discription - Not require
DriverPath = "C:\WINNT\Syste m32\SQLSRV32.DL L"
LastUser = "SA" 'if SA doesn't work, use your UserID
Server = Name of the Sql Server or IP address
DriverName = "SQL Server"

'Create the new DSN key.

lResult = RegCreateKey (HKEY_LOCAL_MAC HINE, _
"SOFTWARE\ODBC\ ODBC.INI\" & DataSourceName, hKeyHandle)

'Set the values of the new DSN key.

lResult = RegSetValueEx(h KeyHandle, "Database", 0&, _
REG_SZ, ByVal DatabaseName, Len(DatabaseNam e))
lResult = RegSetValueEx(h KeyHandle, "Descriptio n", 0&, _
REG_SZ, ByVal Description, Len(Description ))
lResult = RegSetValueEx(h KeyHandle, "Driver", 0&, REG_SZ, _
ByVal DriverPath, Len(DriverPath) )
lResult = RegSetValueEx(h KeyHandle, "LastUser", 0&, _
REG_SZ, ByVal LastUser, Len(LastUser))
lResult = RegSetValueEx(h KeyHandle, "Server", 0&, REG_SZ, _
ByVal Server, Len(Server))

'Close the new DSN key.

lResult = RegCloseKey(hKe yHandle)

'Open ODBC Data Sources key to list the new DSN in the ODBC Manager.
'Specify the new value.
'Close the key.

lResult = RegCreateKey(HK EY_LOCAL_MACHIN E, _
"SOFTWARE\ODBC\ ODBC.INI\ODBC Data Sources", hKeyHandle)
lResult = RegSetValueEx(h KeyHandle, DataSourceName, 0&, _
REG_SZ, ByVal DriverName, Len(DriverName) )
lResult = RegCloseKey(hKe yHandle)

End Sub

'************** *************** *************** ************

Just fill in the parameters above where it says "Specify Parameters".
This will create your dsn and an entry in the registry. You can go to
Start\Settings\ Control Panel\Administr ative Tools\Data
Sources(ODBC)\S ystem DSN tab to see your new dsn.

You can also go to Regedit to

HKEY_LOCAL_MACH INE, "SOFTWARE\ODBC\ ODBC.INI\ODBC Data Sources

and you will see your dsn there too.
Rich

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

Thanks so much, that worked a treat, i was worrying that I would only be
able to use the database from one machine!

Thanks again!

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
Alex & Rich,

The Registry keys you establish in the posted VB code can also
be created by a setup.exe program. The ODE tools in an access developer's
edition include a wizard to produce a slick installation package for an
Access front end. It has a section for adding registry keys.
I've used that route successfully for porting to other machines on our LAN.
But I have a follow up question about how to set up
the rest of the configuration to get the same portability across the internet.

Here's my special trouble spot: the connection has to be made
to an SQL Server "named instance". These run on non-default port numbers;
I know the fixed port number and the server has an internet DNS hostname.
I've used cliconfg.exe running on the remote machine to manually establish
a working connection via TCP/IP by entering the hostname and port number
into the appropriate controls. This builds a "server alias" on the client
so that the ODBC Data Source can connect. I've observed the registry keys
this adds, and I found only two:

HKEY_LOCAL_MACH INE\Software\Mi crosoft\MSSQLSe rver\Client\Con nectTo
contains a <server alias> key with value "DBMSSOCN,<host name>,<port#>"

HKEY_LOCAL_MACH INE\Software\Mi crosoft\MSSQLSe rver\Client\TDS
contains a <server alias> key with value "7.0"
{it's SQL 2000, though - should I worry?)

I then use this <server alias> in place of the <server name> in the
ODBC.INI keys. I'm getting 99.44% of the connection effect.
On the positive side, the "SQL Server ODBC Data Source Test"
sequence on such clients PASSES!- the ODBC data source believes it exists,
and I believe it since it rejected bad passwords and allowed only
good passwords - which only the server could have told it.
I'm assuming that this test sequence also verified that the network
library version numbers are compatible. It reported them so it must
have considered them as test criteria.

Now if the .mdb or .mde file would work I probably wouldn't be posting.

It doesn't. When I run the .mde file, the SQL Server login dialogue
takes 30 seconds after I enter the password and then
coughs up an error string from the Socket library Connect() saying
that the SQL Server could not be found.

Reviewing I see the Linked Table has a Connect string:
"ODBC;DSN=<odbc source>;..." Which names my validated data source,
and also gives the right database name (same code works on the LAN).

The ODBC Data Source passes its connection test. There is no encryption
specified for the SQL server traffic. Do you pros have any idea why the
full client won't connect?

I'd dearly like to ship installation CDs that make these Registry keys
(and then clean them up when you uninstall). I believe they should work.
They don't.

The only small diff I've noted is that when I bring up cliconfg.exe on
a client whose keys were built by setup.exe, I don't see TCP/IP as
an enabled protocol for the SQL Network Client. The ODBC connection test
could only have used TCP/IP. It is happy, so why not Access 97?
The firewall lets both TCP and UDP get through on the port# in question.

The one time I got a good connection front to back was in early experiments.
I'd tried using "hostname:port# \SQLServerInsta nceName" as the ODBC SQL
Server name. It didn't know what to make of this. So I used cliconfg
to make an alias whose spelling exactly matched that string. It worked!
So I went home and wrote tidier looking aliases into my keys and came
back only to find egg on my face. Does cliconfg.exe do something the
key settings alone cannot do? If so, is there a command line way to get
cliconfg to do this during an installation sequence?

Thanks for any hand holding you can offer.

Greg (& Rebecca)
Nov 13 '05 #4
Disclaimer: I am not the Maestro of any of this stuff :).

But using ODBC accross the internet/intranet - kinda sounds like
re-inventing the wheel, ie: you have a Good Year steel belted radial
tire, but are looking to develop a Fred Flintstone wheel (with all due
respect). Across the net I would stick with Asp(x) and ADO for
interfacing with Sql Server. Far more reliable than ODBC.

Matter of fact, the only reason I even use ODBC at all (for Sql Server)
is for the end users who want to see live tables in Access, without
warranty. ODBC has real limited bandwidth compared to ADO, plus, the
connection is constantly open, unlike ADO.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #5
Rich P wrote:
Disclaimer: I am not the Maestro of any of this stuff :).

But using ODBC accross the internet/intranet - kinda sounds like
re-inventing the wheel, ie: you have a Good Year steel belted radial
tire, but are looking to develop a Fred Flintstone wheel (with all due
respect). Across the net I would stick with Asp(x) and ADO for
interfacing with Sql Server. Far more reliable than ODBC.
Granted, but this is a legacy Access97 ap being "upsized" (no sizes
are actually changing) so that the small fixed number of users can
escape from the LAN. The database is relational, and their internet
connectivity to the server is excellent. But I guess we're hitting
"unreliable " aspects of the ODBC - SQL Server link up.

As to car analogies - I'd just say that we've got a vintage Caddy that
we need to take on a long distance drive in an era of high gas prices.
We *could* replace the engine and discard 2/3rds of the steel, but the
ride would never be the same! Those linked tables and bound forms
seem to work fine when I build the ODBC Data Source by hand on each
client - I just can't do that for each user and I want to know how to
automate it reliably.
Matter of fact, the only reason I even use ODBC at all (for Sql Server)
is for the end users who want to see live tables in Access, without
warranty. ODBC has real limited bandwidth compared to ADO, plus, the
connection is constantly open, unlike ADO.

Rich


Nov 13 '05 #6

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

Similar topics

0
2030
by: Vic Spainhower | last post by:
Hello, This is probably not the correct forum to post this problem but I posted it in the Access group but didn't get a reply and I'd like to move forward on this. I have setup an ODBC Connection to a MySQL database (driver version is 3.51) but when I setup the link in MS Access 2002 some of the tables will show #Name? in all of the fields, some will show #Deleted in all of the fields and some will work (except I can't update them). ...
3
3911
by: Richard Muller | last post by:
Hi All, I've got the ASP script shown below that complains as follows: Microsoft OLE DB Provider for ODBC Drivers (0x80004005) Data source name not found and no default driver specified /ShowEvents.asp, line 24 Line 24 of the script is the line:
5
102544
by: SerGioGio | last post by:
Hello, I am going nuts. I am trying to connect to my local ORACLE instance using ODBC. It used to work few weeks ago, but it fails now. Connection with: - SQL*plus: connection works! - DataDirect 5.0 Oracle Wire protocol (3rd party ODBC driver): connection works when I hit the driver's "test connection"
6
3376
by: Anil Kumar Saharan | last post by:
Hi, I have a loopback connection using ODBC in the DLL initialization code of the SQL Server ESP Module (SQL Server 2000). The loopback connection works fine when the DSN is specifed with the "NT Authentication", however the same fails when specified with the "SQL Server user authentication". I have tried
9
17026
by: mcbill20 | last post by:
Hello all. I just installed Oracle 10g developer tools on a machine running XP Pro and Office XP. Before this I had just the Oracle 9 client installed. I the previous configuration, I was able to access any of the Oracle tables on another machine but now I am having problems. Unfortunately, I don't remember the correct syntax for the ODBC connect string and I am hoping that is my whole problem. I am trying to connect to an Oracle 9...
0
3731
by: Igor | last post by:
An error "ODBC connection to failed" is raised when I am trying to get data from a table in Microsoft Access (97, or 2000) which is actually a linked table to another table in SQL Server 7 . The exception is raised from a Web .Net app while exactly the same code works fine in Windows .Net app. That makes me thinking the issue somehow is related to security context. Anyway I do not know how to solve the problem, and any help is...
0
12061
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i try running it: Server Error in '/CinemaBookingSystem' Application. -------------------------------------------------------------------------------- ERROR General error Unable to open registry key 'Temporary (volatile) Jet DSN for process
3
3319
by: TheMaxx | last post by:
I've created ODBC DSN for sql server. When i connect from win application works OK. When i make WebService (on same machine) that connects to that ODBC connection fails: Error: Server was unable to process request. --ERROR Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection. ERROR Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server
1
3591
by: Pradeep83 | last post by:
Hi All Problem : I am unable to retrieve the data from the table in postgres database using C application which i have written in solaris os. Query: How to check whether connection is there between postgres database and C application(which we have written for accessing the database) ? My code is comiling successfully if i run it then its giving o/p as following : output
1
5405
by: mikerudy | last post by:
I have an 3rd-party application that uses a SQL back-end, but uses Access 2000 (linked tables all using the same DSN) as an intermediary. We recently upgraded from SQL 7 to SQL 2005, which went fine. Now, however, we want to setup SQL Mirroring to provide automatic failover. The mirroring works fine. In my test environment, the mirror server becomes active automatically when the service is stopped on the principal server. I can see...
0
8760
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8670
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4433
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2458
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2070
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.