views:

346

answers:

2

Hi,

I've done a fair bit of mysql php programming but am pretty new to asp/access etc.

This will either be incredibly easy or impossible!

SUMMARY:

I'm trying to transfer a web application from a corporate network to an external web host for testing and don't know how to connect the pages to the database on the new server.

BACKGROUND:

I've inherited a (ms access) database driven website from a corporate server and have been asked to pull it apart and document it so that there's no single point of failure issue with it (the original programmer disappeared long ago)

It was hosted on an ms sql server on the corporate network.

I've obtained some free hosting for access driven websites at www.jabry.com and hoped to transfer the whole application to there and use that as a test bed.

I got a copy of the .mdb file and uploaded it to jabry. My question is what connection should i use to the new database?

THIS IS THE OLD CONNECTION INSTRUCTION :

dim objConn
set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "PROVIDER=SQLOLEDB;DATA SOURCE=UKNTHSQL900;UID=****User;PWD=***able8; DATABASE=PropertyRegister"

JABRY RECOMMEND USING :

Dim Conn
Set Conn = Server.CreateObject("ADODB.Connection")
strConnection = "DRIVER=Microsoft Access Driver(*.mdb);DBQ=" & Server.MapPath("/USERNAME/db/yourdatabase.mdb")
oConn.Open(strConnection)

I've tried various permutations to get this to work, but after a couple of hours(!) thought I'd better get some help.

Can I use a dsnless connection when a password is required? Are the two server types completely incompatible? Please help!

+3  A: 

This site should help: http://www.connectionstrings.com/access.

  dbfile=Server.MapPath("..\YourDB.mdb")
  Set objConn=Server.CreateObject("ADODB.Connection")

  objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
              "Data Source=" & dbfile & ";Jet OLEDB:Database Password=PW"

The "..\" part depends, as you may imagine, on where you are running the code and where the database resides.

EDIT re Comment: You can also use ADO to enumerate the tables and queries held in the database.

   ''cn = Your connection
   Set rs = cn.OpenSchema(20, Array(Empty, Empty, Empty))

   Do While Not rs.EOF
      '' This is vbscript / vba, as per comments, 
      '' change to rs("Table_Type") for ASP ...
      If rs!TABLE_TYPE <> "View" Then
         '' ... and this to rs("TABLE_NAME") ...
         s = s & rs!TABLE_NAME & vbCrLf
      End If
      rs.MoveNext
   Loop

   rs.Close
   Set rs = Nothing

   '' ... and this to Response.Write s
   MsgBox s

More info: http://msdn.microsoft.com/en-us/library/aa165325%28office.10%29.aspx

Remou
Thanks for the quick response gents. Used both your suggestions and got this error:Microsoft JET Database Engine error '80040e37'The Microsoft Jet database engine cannot find the input table or query 'Person'. Make sure it exists and that its name is spelled correctly. Which I'm guessing means that it found the database ok but couldn't find the table 'Person' named in the query. That sound right?Now I guess I need to find someone with access to check the database is what it was supposed to be!
Derek
I have added a little.
Remou
@Derek: After trying @Remou's suggesting for listing the avaialable tables, if the Person table is listed there, you might want to post your SQL, and a little something of the code context. If it's not listed, then you have a different problem entirely, possibly related to permissions somewhere along the line (NTFS permissions or Jet ULS).
David-W-Fenton
Remou I could kiss you! Had to modify your code a little. Changed rs!Table_Type to rs("Table_Type") and rs!TABLE_NAME to rs("TABLE_NAME") as they were causing vb errors but then it worked! Tables were listed as dbo_Person rather than Person etc. (something to do with the access export process?) Changed the table name in my query and it worked! So if I rename the tables in the db eg. (dbo_Person back to Person) presumably the rest of the web app will work unchanged? Thanks a billion.
Derek
Oh one more thing, had to change "MsgBox s" to "response.write s" as this threw a permissions error
Derek
Oops. It was a very translation from vba :) I can't immediately think of any reason why changing the table names would not work.
Remou
Update: Renamed tables as above and everything now working. Thanks again. Saved me a lot of hair pulling and tears.
Derek
A: 

How did you obtain the .mdb file? If you exported from an SQL Server database to an Access database file, it may or may not work depending on the features used in the SQL Server database. If it was used just for "dumb" storage, the Access database file can do that, but if it used features like stored procedures, user defined functions or triggers, the Access database file can't replicate that.

If the Access database has a password set, you have to specify that in the connection string. The user name that you specify is "Admin", so the connection string should look something like:

"Driver={Microsoft Access Driver (*.mdb)};Dbq=" & Server.MapPath("/YourUserName/db/TheDatabaseFileName.mdb") & ";Uid=Admin;Pwd=ThePassword;"

Of course you have to substitute the YourUserName, TheDatabaseFileName and ThePassword parts with the actual values. You also have to have uploaded the database into the db folder on the server, which is set up with the proper file permissions for the web application to be able to write to the database file.

What the web hotel has recommended is an ODBC driver, but I would rather use a JET driver if possible. You can find a lot of examples of connecion strings for Access here: http://www.connectionstrings.com/access

Guffa
Thanks for the quick response gents. Used both your suggestions and got this error:Microsoft JET Database Engine error '80040e37'The Microsoft Jet database engine cannot find the input table or query 'Person'. Make sure it exists and that its name is spelled correctly. Which I'm guessing means that it found the database ok but couldn't find the table 'Person' named in the query. That sound right?Now I guess I need to find someone with access to check the database is what it was supposed to be!
Derek
@Guffa: what do you mean by "JET" driver? There is really no such thing. When you're accessing Jet/ACE data from ASP or PHP or anything else other than Access, you have to use ODBC or OLEDB. There are no other choices. OLEDB is the usual choice with ASP, but perhaps the hosting site is providing lowest-common-denominator instructions for all server-side scripting languages, and maybe some of them don't support OLEDB.
David-W-Fenton
@David: By JET driver I mean the driver named "Microsoft.Jet.OLEDB.4.0", so it's the OleDb driver.
Guffa