Connecting to an Access database in Classic ASP using an ADODB object - ms-access

I am new to classic ASP. I would rather ask question than do hour of research to solve my problem.
I am accessing access database and getting the following error.
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
/default1.asp, line 30
The culprit line is this
Set MyConn = Server.CreateObject("ADODB.Connection")
MdbFilePath = Server.MapPath("c:\database\MyDatabase.mdb")
Well, I do not have Access installed but I copied the .mdb file to the specified folder, will it work that way? I am familiar with SQL Server, and that has to run in order to retrieve data from it.
It uses ADODB but I can't file the DLL. Can someone specify the DLL for me. What I have to do to get it working. Just registering it will work using regsvr32 my.dll?
I could not find a connection string (I usually use a connection string to connect to my SQL Server). Do I need one for Access database in this case?
Please help

It's been a few years for me, so this answer might be a little out of date. Also, since the Access db ends in .mdb, I'm assuming that it's a pre-2007 database.
Yes, just the file should work. Access does not need to run, it just needs to read the file. However, you may need certain components installed to talk to the Access database (used to be MDAC
- http://www.microsoft.com/download/en/details.aspx?id=1953, not 100% certain if it still is). MDAC contains the JET engine, which classic ASP uses to talk to Access files.
As for the connection string, this web site that provides some examples of access connection strings: http://connectionstrings.com/access
edit - adding more info
Just in case I'm not following the comments correctly, here's an example of how to connect to the Access database through Classic ASP:
Set MyConn = Server.CreateObject("ADODB.Connection")
MdbFilePath = "c:\database\MyDatabase.mdb" ''# Server.MapPath is not needed, since we are providing the whole path already
MyConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & MdbFilePath
When running the code above, do you receive the error still? Also, what's the set up you're running (IIS7, IIS6, 32bit, 64bit)?

Related

LotusScript - How to connect to MySQL?

Sorry for possible dublicate.
I am trying to connect to my MySQL database from my LotusScript code (in some of my legacy projects):
Option Public
Option Declare
UseLSX "*LSXODBC"
Sub Initialize
Dim mysqlConnection As New ODBCConnection
Dim sqlQuery As New ODBCQuery
Dim result As New ODBCResultSet
Call mysqlConnection.ConnectTo("url","root","111111")
If Not mysqlConnection.IsConnected Then
MessageBox "No connection. Try again later."
Exit Sub
Else
MessageBox "Connection success."
End If
End Sub
I can't figure out what is the correct way to set the url of my database in LotusScript. I have already tried many variants of possible solutions, but nothing worked, also found many different urls, but also not helped.
Situation:
For example, I am trying to connect to my localhost MySQL base in port 3306 with name "test_db".
Question:
How must the url looks like for this?
p.s. also, if you have more possible ways to connect to MySQL DB from LotusScript - I will be very glad to see them.
Thanks.
As per the documentation for the ConnectTo method of ODBCConnetion class, you don't specify a URL. You specify a Data Source Name, otherwise known as a DSN. This is a name that you assign when you configure a connection in the 'Data Sources (ODBC)' tool on the Windows machine where the code will be executing.
On Windows 10, the 'Data Sources (ODBC)' tool is found in the Control Panel listed under Administrative Tools. On a Windows 2008 server that I happen to have handy, Administrative Tools is directly on the Start Menu. I'm sure they've hidden it in other places on other Windows versions. (I have a dim memory of it being under 'Accessories' on some versions.)
Note that on 64 bit versions of Windows, you need to be cognizant of whether your code is running in a 32 bit environment - as it is if it runs in the Notes client, or in a 64 bit environment, which it might be if it is running in background on a Domino server. There are separate 32 and 64 bit versions of the 'Data Sources (ODBC)' tool, and it does matter which one you use. If you're at all unsure, run them both and configure the same DSN name in each of them,

The Microsoft Jet database engine cannot open the file on Network Location

I am developing an ASP classic website that connects to a MS Access database and display data at real time (I know MS Access is not the best option for this purpose, but my company uses it for everything, so I just decide to use it for now). When the MS database is on my hard disk drive (C:), it works fine. But when I move the database to one of the network locations, such as U:\tracking, it gives me this error:
Microsoft JET Database Engine error '80004005'
The Microsoft Jet database engine cannot open the file 'U:\tracking\database.mdb'. It is already opened exclusively by another user, or you need permission to view its data.
I know it is probably due to the security permission (read and write) about creating temporary files (.ldb) for MS Access database. I reset the security permission on the U:\tracking folder, which contains the database, but it did not work. I even gave full control to every account listed in the "Group and user names" session, but the error was still there.
I also checked my Authentication setting in my IIS manager. The only enabled setting is Anonymous Authentication, and I use Application pool identity at this point. If I use specific user, I may add it to the above permission list and give it the appropriate permission, but I cannot guarantee it is appropriate. Any ideas about what I should do to connect to the database on the network location? Any help would be appreciated!
Following is the simple code I use to connect to the database:
Dim dbCon
Set dbCon = Server.CreateObject("ADODB.Connection")
dbCon.Provider = "Microsoft.Jet.OLEDB.4.0"
dbCon.Open = "U:\tracking\database.mdb"
Consider using the ASO connection string parameter as this W3Schools page indicates.
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0"
conn.open server.mappath("database.mdb")
conn.close
%>
Also, path names do not need to be explicitly defined if server map targets the root directory. This is especially true since backslashes prove problematic for web URLs that use forward slashes.

Connecting to remote mySQL via Excel VBA

Likely a dumb question but brain isn't piecing this together---
tl;dr: My main question is how do I choose the right parameters for my connection string? How do I determine what my driver should be? Provider? Option? Where do I find a list of acceptable parameters? How do I choose between ADO and OLE?
Objective: to connect to a hosted mySQL db of which I am admin.
Problem: creating a successful connection string / choosing the right parameters.
I'm new to referencing remote databases. Been looking all day today and yesterday; there are tons of articles and posts out there but nothing is working for me--I'm just trying to replicate what I see being done when I need to just design the string properly, but I don't know where to start.
I've tried using ActiveX Data Objects 2.7, 2.8 and 6.1 libraries. Also tried using OLE DB Simple Provider 1.5 Library. Below tests are using ADO 6.1.
Tried these connection strings:
DRIVER={MySQL ODBC 5.3 Unicode Driver};SERVER=ipaddress;PROVIDER=SQLOLEDB;DATABASE=xxx;UID=xxx;PWD=xxx;
---Error: waits ~30 seconds, times out and says Invalid Connection String Attribute
DRIVER={MySQL ODBC 5.3 Unicode Driver};SERVER=ipaddress;PROVIDER=Microsoft.Jet.OLEDB.4.0;DATABASE=db_name;USER=xxx;PASSWORD=xxx;
---Error: immediately errors and says cannot find installable ISAM
SERVER=ipaddress;PROVIDER=SQLOLEDB;DATABASE=xxx;UID=xxx;PWD=xxx;
---Error: waits ~30 seconds, times out and says SQL Database does not exist or access denied
I'm sure i've added the correct user with password and permissions. I haven't done anything with DSN.
I'm on win8.1 x64 using Excel 2013. Any advice is much appreciated!!

Sharepoint Designer 2007 ODBC database connection to MySQL impossible?

I'm trying to create a Database Connection to ODBC data sources in SPD 2007 and am having absolutely no luck. I've had some success using an SqlDataSource control, however. I don't know if SPD's database connection support is just broken or what. Googling has turned up others having issues but no definitive answers.
So, my two data sources are MySQL 5.1 ODBC and ProvideX ODBC. I pretty much have the same trouble with either, so I'll just focus on MySQL.
I've got a system DSN on the machine running SPD that is successfully connecting to the MySQL database. (This DSN also exists on the server running Sharepoint, if that matters at this time).
In SPD, I go the Data Source Library, expand Database Connection, and choose Connect to a Database. I then click on Configure Database Connection. Since neither of the providers in this dialog are appropriate, I choose "Use a custom connection string". I then set the provider to "Microsoft .Net....ODBC" and at this point I've tried the following connection strings.
First the DSN attempts:
Dsn=TheOneICreated (this one works from the SqlDataSource control)
and
Data Source=TheOneICreated
Then the more direct approach:
Driver={MySQL ODBC 5.1 Driver};Server=myServerIP;Database=dbName;User=username;Password=password;Option=3
The error I get back is always the same -
"Server Error: An error occurred while
retrieving the list of Databases from
: The server for the data source
returned a non-specific error when
trying to execute your query. Check
the format and content of your query
and try again. If the problem
persists, contact the server
administrator."
Am I fighting a losing battle here?
It looks like SD could be enumerating databases and/or tables so it has a list of tables and fields to 'help' you along....
Just a clarifying question or two..
Could this happen because SD is expecting a different way of enumerating tables? (Does it actually work with MySQL or anything ?)
What does your ODBC trace look like? (If #1 is true, you'll be able to see it and possibly create supporting views...if you truly need it to work with this particular dbms...)
Is this connection accessed from the sharepoint server? If so, do you need to define your dsn & driver there?

classic asp connecting to access database, file not found

I am having to work in classic ASP for a small job.
I am trying to get the site running on my computer to test. I am running Windows 7 and IIS 7.
I get an error when running from local host and on checking the logs I get the error:
80004005 | Could_not_find_file_'c:\inetpub\wwwroot\sc\website\data\si.mdb'
My code is like so
dim objConn
dim objRS
set objConn = Server.CreateObject("ADODB.Connection")
objConn.Provider="Microsoft.Jet.OLEDB.4.0"
Set objRS = Server.CreateObject("ADODB.Recordset")
objConn.Open("c:/inetpub/wwwroot/sc/website/data/si.mdb")
This is the exact path to the file however.
Anyone know how I can access this? Is the code wrong or are there IIS settings I need to set?
I do not have any version of Office installed, would that cause a problem?
I have tried lots of different paths and provider settings but none have worked.
Edit
The code I am working on actually didn't have any connection string details in the code but the person said it still worked on thier computer as a friend setup the test environment.
He doesn't recall how his friend setup but said " What I remember from watching him, he connected to the database through Data Sources (ODBC) because as you said in the code theres no direct path as its using a 'global something' (dont know the right term)."
You could try using Process Monitor to see exactly which file is not being found or it is being caused by a permissions issue.
Also, although using forward slashes instead of backslashes isn't usually a problem, you may want to try changing that in case it makes any difference.
If you're using an x64 version of windows, JET is not supported in this mode, though you can get around it by configuring IIS to run x32 applications. To do this, run the following at the command line:
cscript.exe adsutil.vbs set W3SVC/AppPools/Enable32BitAppOnWin64 "true"
iisreset
The second command may not be required, but I'm guessing that you would probably need to restart IIS before this change takes effect.
It sounds like the code was previously set to use a global DSN, hence the lack of a path in the connection string, though there should have still been some kind of connection details (like the DSN name).
This may be a permissions issue.
An easy way to check would be to give full access to everyone for the directory the file is in.
Maybe you could use the Server.MapPath function as used here http://www.aspwebpro.com/tutorials/asp/dbconnectionopen.asp
Your connection string doesn't look right to me.
See if this helps.
EDIT: Do you have JET oledb provider installed?
EDIT2: Check for existence of oledb provider with help from this question.
How to check if an OLEDB driver is installed on the system?
I answered a potentially related question the other day. Are you running 64-bit windows 7? If so there is absolutely NO Jet support for x64 OSes. In a real .NET application you could simply recompile the application with x86 as the target. But in your case I am not sure of the solution.
Seth
Why does your string say:
"c:/inetpub/wwwroot/sc/website/data/si.mdb"
instead of the normal windows path
"c:\inetpub\wwwroot\sc\website\data\si.mdb"
Also, you could go to Control Panel->Administrative Tools->Data Source (ODBC) and create a new named DSN under the System tab. Name it si for example and make sure the type is access, give it the right path to the access db and then your code would just be:
dim objConn
set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open("si")