473,382 Members | 1,367 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,382 software developers and data experts.

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 40367
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_MACHINE = &H80000002

Private Declare Function RegCreateKey Lib "advapi32.dll" _
Alias "RegCreateKeyA" (ByVal hKey As Long, _
ByVal lpSubKey As String, phkResult As Long) As Long

Private Declare Function RegSetValueEx Lib "advapi32.dll" 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.dll" _
(ByVal hKey As Long) As Long
Sub createSystemODBCdsn()
'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\System32\SQLSRV32.DLL"
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_MACHINE, _
"SOFTWARE\ODBC\ODBC.INI\" & DataSourceName, hKeyHandle)

'Set the values of the new DSN key.

lResult = RegSetValueEx(hKeyHandle, "Database", 0&, _
REG_SZ, ByVal DatabaseName, Len(DatabaseName))
lResult = RegSetValueEx(hKeyHandle, "Description", 0&, _
REG_SZ, ByVal Description, Len(Description))
lResult = RegSetValueEx(hKeyHandle, "Driver", 0&, REG_SZ, _
ByVal DriverPath, Len(DriverPath))
lResult = RegSetValueEx(hKeyHandle, "LastUser", 0&, _
REG_SZ, ByVal LastUser, Len(LastUser))
lResult = RegSetValueEx(hKeyHandle, "Server", 0&, REG_SZ, _
ByVal Server, Len(Server))

'Close the new DSN key.

lResult = RegCloseKey(hKeyHandle)

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

lResult = RegCreateKey(HKEY_LOCAL_MACHINE, _
"SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources", hKeyHandle)
lResult = RegSetValueEx(hKeyHandle, DataSourceName, 0&, _
REG_SZ, ByVal DriverName, Len(DriverName))
lResult = RegCloseKey(hKeyHandle)

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\Administrative Tools\Data
Sources(ODBC)\System DSN tab to see your new dsn.

You can also go to Regedit to

HKEY_LOCAL_MACHINE, "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_MACHINE\Software\Microsoft\MSSQLServer\ Client\ConnectTo
contains a <server alias> key with value "DBMSSOCN,<hostname>,<port#>"

HKEY_LOCAL_MACHINE\Software\Microsoft\MSSQLServer\ 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=<odbcsource>;..." 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#\SQLServerInstanceName" 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
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...
3
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...
5
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! -...
6
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...
9
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...
0
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...
0
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...
3
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...
1
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...
1
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.