Hi all!
Ok today for the first time I get the chance to finally look at office 2007 and upgrading my access db from 2002 (our entire workplace is upgrading to 2007 and our db is going with it)
The access itself is used mainly as a front end to a back end ms sql 2005 database, with a smattering of local tables in the db too.
So conversion ran well, then it came to testing the code.
Up sprang forth the following error....
odbcdirect is no longer supported rewrite the code to use ado instead of dao
`Oh bugger` was my first thought, knowing the amount of code in our db. I noted that none of the `features no longer available in access 2007` guides id read mentioned this!
So I do some research to see the issues in hand, and from that what it takes to convert. The MS examples were a bit lacking, and other examples dotted around varied in response. So I thought id ask opinions here.
The first port of call when my access opens is to try to create a basic connection to the ms sql server without actually accessing any data, to check the database link itself is ok (we can trap for problems such as user has access denied or doesnt have permissions set up on the ms sql server to access the database) - at this point in time there may be no tables linked to our database.
I normally do this with a code snippet of
I can't quite work out the equivalent code using an ADODB.Connection
I presume the default way of linking tables in 2007 is via ODBC link tables so I do need to check if the connection works. ado != ODBC is it, so checking an ado connection wouldnt give me what im after?
Another question, heres an example of my opening a recordset in current code...
Code im already using using ado connections (to execute stored procedures from access) goes something like
I see lots of examples using currentproject.connection, but I wager this doesnt mean I can share multiple seperate recordsets down the same connection at the same time - should I be creating my own adodb connection each time or only using currentproject.connection. I don't understand how that works - theoretically your access may be connected to several back end db's - what does currentproject.connection actually point to? Im guessing currentproject.connection = linked tables (which is what most of my code based querying accesses)
Hitting the server direct in code based queries or converting lots of things to pass through queries is not an option, given the volume of work, and dynamic nature of much of it.
So with the above I supose im asking - what kind of connection is required on the first example above (currentproject.connection - and can this share multiple live recordsets down it at the same time?), and is the ado stored procedure example still valid, or a little `long winded` compaired to current good working practise examples!
Many thanks in advance for any input,
Martin
Ok today for the first time I get the chance to finally look at office 2007 and upgrading my access db from 2002 (our entire workplace is upgrading to 2007 and our db is going with it)
The access itself is used mainly as a front end to a back end ms sql 2005 database, with a smattering of local tables in the db too.
So conversion ran well, then it came to testing the code.
Up sprang forth the following error....
odbcdirect is no longer supported rewrite the code to use ado instead of dao
`Oh bugger` was my first thought, knowing the amount of code in our db. I noted that none of the `features no longer available in access 2007` guides id read mentioned this!
So I do some research to see the issues in hand, and from that what it takes to convert. The MS examples were a bit lacking, and other examples dotted around varied in response. So I thought id ask opinions here.
The first port of call when my access opens is to try to create a basic connection to the ms sql server without actually accessing any data, to check the database link itself is ok (we can trap for problems such as user has access denied or doesnt have permissions set up on the ms sql server to access the database) - at this point in time there may be no tables linked to our database.
I normally do this with a code snippet of
Code:
On Error Resume Next
Err.Clear
Dim wrkODBC As Workspace
Dim conPubs As Connection
Set wrkODBC = CreateWorkspace("", "admin", "", dbUseODBC)
Set conPubs = wrkODBC.OpenConnection("", dbDriverNoPrompt, False, getODBCConnectionString)
If Err.number <> 0 Then
' handle error accordingly
End If
I can't quite work out the equivalent code using an ADODB.Connection
I presume the default way of linking tables in 2007 is via ODBC link tables so I do need to check if the connection works. ado != ODBC is it, so checking an ado connection wouldnt give me what im after?
Another question, heres an example of my opening a recordset in current code...
Code:
Dim wrkODBC As Workspace
Dim conPubs As Connection
Dim rs As Recordset
Set wrkODBC = CreateWorkspace("", "admin", "", dbUseODBC)
Set conPubs = wrkODBC.OpenConnection("", , False, getODBCConnectionString)
Set rs = conPubs.OpenRecordset("SELECT fields FROM mytable", dbOpenSnapshot)
Code im already using using ado connections (to execute stored procedures from access) goes something like
Code:
Dim objConn As ADODB.Connection
Dim objCmd As ADODB.Command
Dim sDataConnect As String
Dim lngErrorNum As Long
' Instantiate a database connection
Set objConn = CreateObject("ADODB.Connection")
' Create an ADO connect string
sDataConnect = getOLEConnectionString
' Open a database connection
objConn.Open sDataConnect
Set objCmd = CreateObject("ADODB.Command")
With objCmd
.ActiveConnection = objConn
.CommandType = adCmdStoredProc
.CommandText = "dbo.mystoredproc"
etc.etc.
.Execute , , adExecuteNoRecords
lngErrorNum = .Parameters.item("@err")
etc.etc.
End With
Set objCmd = nothing
objConn.close
Set objConn = nothing
Hitting the server direct in code based queries or converting lots of things to pass through queries is not an option, given the volume of work, and dynamic nature of much of it.
So with the above I supose im asking - what kind of connection is required on the first example above (currentproject.connection - and can this share multiple live recordsets down it at the same time?), and is the ado stored procedure example still valid, or a little `long winded` compaired to current good working practise examples!
Many thanks in advance for any input,
Martin