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

Problem connecting to SQL Server from Access Database

Dear all,

We recently migrated a SQL database from one server to another. Now,
when you try to run some code in an Access Database which links to the
SQL one, you get a 3704 error "Operation is not allowed when the
object is closed". I think this means that the connection between the
Access DB and SQL Server has not been made.

- The IP address of the new server is the same as the old one and the
host file on the client PCs has been updated to reflect the name
change.
- The server name in the connection details has been changed to the
new server name in the constants section of our VBA code.
- The new server is running SQL Server 8.0 on MS Server 2003
- The old server was running NT.
- When you hit Debug the line of code that closes the connection
(cn.Close) is highlighted as it has nothing to close (I think).

Everything else is exactly the same. Is there something I'm missing?
Any help would be greatly appreciated!

Many thanks - David

Jun 27 '08 #1
8 1777
Hi Dave,

Have you tried creating a new ODBC Dsn from Control panel since the DB
migration? Try creating a new ODBC Dsn from the Control Panel and then
try connecting to a table in the DB using this Dsn. If you can't create
the Dsn (you can't see the server from the Control Panel) then it is a
network problem. If you can create the Dsn but cannot access/see any
data in a data table from you mdb - then there is either a problem with
the workstation or with the DB. If you can't see data from the ODBC
connection - try creating a new blank mdb and see if you can see any
data from the ODBC connection in the new mdb.

If everything works normal with the ODBC connection then there is
something wrong with the code statement you are using. Perhaps you
could share your code statement.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #2
Hi Rich,

Our code is a follows:

Public Function fnbValidUserIDPassword(ByVal stUserID As String, ByVal
stPassword As String) As Boolean
On Error GoTo Exit_fnbValidUserIDPassword
Dim mEncrypt As New MessageDigest5
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim rst As Recordset
Dim stSQL As String

fnbValidUserIDPassword = False

stSQL = "SELECT count(*) as UserCount from Users Where UserID = '"
& stUserID & "' and Password = '" & stPassword & "'"
cn.Open (gcstSQLServer_Directa)
rs.Open stSQL, cn, adOpenDynamic, adLockReadOnly

If Not (rs.EOF) Then
rs.MoveFirst
fnbValidUserIDPassword = (CInt(rs![UserCount]) = 1)
If Not (fnbValidUserIDPassword) Then
stSQL = "SELECT count(*) as UserCount from Authoriser
where AuthoriserID = '" & stUserID & "' and Password = '" & stPassword
& "' and DirectaUser = false"
Set rst = CurrentDb.OpenRecordset(stSQL, dbOpenSnapshot,
dbInconsistent, dbReadOnly)
If Not (rst.EOF) Then
rst.MoveFirst
fnbValidUserIDPassword = (CInt(rst!UserCount) = 1)
End If
End If
End If

Exit_fnbValidUserIDPassword:

cn.Close
Set cn = Nothing
Set rs = Nothing
End Function

****END OF CODE*****

The cn.Open (gcstSQLServer_Directa) part refers to our constant
section of the code - I've tested it and the connection settings are
definitely correct.

Cheers - David


On Jun 12, 4:14 pm, Rich P <rpng...@aol.comwrote:
Hi Dave,

Have you tried creating a new ODBC Dsn from Control panel since the DB
migration? Try creating a new ODBC Dsn from the Control Panel and then
try connecting to a table in the DB using this Dsn. If you can't create
the Dsn (you can't see the server from the Control Panel) then it is a
network problem. If you can create the Dsn but cannot access/see any
data in a data table from you mdb - then there is either a problem with
the workstation or with the DB. If you can't see data from the ODBC
connection - try creating a new blank mdb and see if you can see any
data from the ODBC connection in the new mdb.

If everything works normal with the ODBC connection then there is
something wrong with the code statement you are using. Perhaps you
could share your code statement.

Rich

*** Sent via Developersdexhttp://www.developersdex.com***
Jun 27 '08 #3
It would seem that something closes the connection, cn, before
"cn.Close" errors. What? I see nothing in the code you show us that
does; the connection is open at "rs.Open stSQL, cn, adOpenDynamic,
adLockReadOnly" or we'd error out there and "cn" is not referenced
again until the line that errors.

So where?

The presence of "Exit_fnbValidUserIDPassword:" implies the presence
of "Err_fnbValidUserIDPassword:" or similar. One can guess (one chance
in a hundred) that code referenced by that label closes the
connection, cn.

On Jun 13, 6:20*am, Daveo <writetoda...@gmail.comwrote:
Hi Rich,

Our code is a follows:

Public Function fnbValidUserIDPassword(ByVal stUserID As String, ByVal
stPassword As String) As Boolean
On Error GoTo Exit_fnbValidUserIDPassword
Dim mEncrypt As New MessageDigest5
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim rst As Recordset
Dim stSQL As String

* * fnbValidUserIDPassword = False

* * stSQL = "SELECT count(*) as UserCount from Users Where UserID = '"
& stUserID & "' and Password = '" & stPassword & "'"
* * cn.Open (gcstSQLServer_Directa)
* * rs.Open stSQL, cn, adOpenDynamic, adLockReadOnly

* * If Not (rs.EOF) Then
* * * * rs.MoveFirst
* * * * fnbValidUserIDPassword = (CInt(rs![UserCount]) = 1)
* * * * If Not (fnbValidUserIDPassword) Then
* * * * * * stSQL = "SELECT count(*) as UserCount from Authoriser
where AuthoriserID = '" & stUserID & "' and Password = '" & stPassword
& "' and DirectaUser = false"
* * * * * * Set rst = CurrentDb.OpenRecordset(stSQL, dbOpenSnapshot,
dbInconsistent, dbReadOnly)
* * * * * * If Not (rst.EOF) Then
* * * * * * * * rst.MoveFirst
* * * * * * * * fnbValidUserIDPassword = (CInt(rst!UserCount) = 1)
* * * * * * End If
* * * * End If
* * End If

Exit_fnbValidUserIDPassword:

* * cn.Close
* * Set cn = Nothing
* * Set rs = Nothing
End Function

****END OF CODE*****

The cn.Open (gcstSQLServer_Directa) part refers to our constant
section of the code - I've tested it and the connection settings are
definitely correct.

Cheers - David

On Jun 12, 4:14 pm, Rich P <rpng...@aol.comwrote:
Hi Dave,
Have you tried creating a new ODBC Dsn from Control panel since the DB
migration? *Try creating a new ODBC Dsn from the Control Panel and then
try connecting to a table in the DB using this Dsn. *If you can't create
the Dsn (you can't see the server from the Control Panel) then it is a
network problem. *If you can create the Dsn but cannot access/see any
data in a data table from you mdb - then there is either a problem with
the workstation or with the DB. *If you can't see data from the ODBC
connection - try creating a new blank mdb and see if you can see any
data from the ODBC connection in the new mdb.
If everything works normal with the ODBC connection then there is
something wrong with the code statement you are using. *Perhaps you
could share your code statement.
Rich
*** Sent via Developersdexhttp://www.developersdex.com***
Jun 27 '08 #4
Hi Lyle,

Thanks for your reply. Am I right in thinking that the code is
hitting an error and (as per On Error GoTo
Exit_fnbValidUserIDPassword ) is closing the connection? Could it be
trying to close the connection before it is opened?

Many thanks,

David

Jun 27 '08 #5
On Jun 13, 8:15*am, Daveo <writetoda...@gmail.comwrote:
Hi Lyle,

Thanks for your reply. *Am I right in thinking that the code is
hitting an error and (as per On Error GoTo
Exit_fnbValidUserIDPassword ) is closing the connection? *Could it be
trying to close the connection before it is opened?

Many thanks,

David
That's my guess. You have all the code. Is there and "On Error
Goto ..." line? It seems something is closing CN.

If you add the line, "Debug.Print cn.State"

before cn.Close

then the immediate window shows 0 (zero)?

Jun 27 '08 #6
Hi Lyle,

Thanks for the response - yes I get a 0 when adding the line. The
only On Error Goto.. line is On Error GoTo
Exit_fnbValidUserIDPassword.

Many thanks,

David

Jun 27 '08 #7
If you comment this line out and run the code, you may find the
initial, real error.
On Jun 13, 8:46*am, Daveo <writetoda...@gmail.comwrote:
Hi Lyle,

Thanks for the response - yes I get a 0 when adding the line. *The
only On Error Goto.. line is On Error GoTo
Exit_fnbValidUserIDPassword.

Many thanks,

David
Jun 27 '08 #8
Hi Lyle,

Thanks for all your help - it appears that someone (helpfully) decided
to change the uid and pw on the database without telling anyone.
Should have really checked that before bothering you, but everything
was supposed to be identical.
Thanks again - David
Jun 27 '08 #9

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

Similar topics

1
by: Marino | last post by:
Hi all, I have a Windows 2003 server, which is also a terminal server for application, with sql 2000 installed. My company has developed an application that uses SQL 2000 as its database. The...
4
by: Ian Davies | last post by:
Hello all The following code allows me to connect to a local MySQL database on my pc from a VB6 project. **************************************************************************** ** Dim...
12
by: Ann Marinas | last post by:
Hi all, I would like to ask for some help regarding separating the asp.net webserver and the sql server. I have created an asp.net application for a certain company. Initially, we installed...
4
by: kthiagar | last post by:
Hi I am trying to connect to a password protected access file from VB.NET. I have no problem in connecting to Access, if I remove the password. This is what I am doing: In the server explorer,...
1
by: Chris Love | last post by:
I have already asked this, but no one seems to know the answer. Here is the timeline. I wanted to use the membership/roles functionality in a site. I got all sorts of errors trying to get this...
2
by: shapper | last post by:
Hello, I added some profile properties to my web.config file. Then I started to use my profile properties in a page class and I get an error: An error has occurred while establishing a...
2
by: Patrick F | last post by:
Hi, i have SQL Server 2005 and a database set that is called, myCompany the problem is that i cant connect from my page to it, here is from the web.config: ( i have got this connectionstring from...
0
by: sangkatte | last post by:
While running asp website designed with webparts, I got the following error. Please tell me how to solve this problem. An error has occurred while establishing a connection to the server. When...
2
by: orandov | last post by:
Hi, I am having a problem connecting my .net applications from the application server to the database server. When I run the application from my windows xp (sp2) box it works fine. When I try to...
1
by: john20 | last post by:
Hi All, I am trying to use webpart in my page for that i am putting webpartmanager and webpartzone. but as soon as i am putting webpartmanger in the page it is giving me below error, let me...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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...
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
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,...

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.