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,
Related
I am using the Microsoft Access ODBC driver (installed by AccessDatabaseEngine_X64.exe) on my local machine to run "SQL" statements on an older Access database. Everything works fine here.
But now I am deploying it to a Docker container (using mcr.microsoft.com/windows:1809-amd64) as the base image. My dockerfile installs .NET Core and also AccessDatabaseEngine_X64.exe. But when I run my app on the container, it executes hundreds of "SQL" statements just fine but then suddenly gets an AccessViolationException. I eventually figured out after running the same transaction script over and over that it was always crashing on the same query -- and the query contains IsNull().
I confirmed the driver files on the container match that of my local machine (both 64-bit only). For testing, I am using the exact same database on the local machine and container -- but that doesn't really matter because the database can be empty to get the access violation.
I've reduced the test application down to this simple program:
const string connectionString = #"Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=db\Test.mdb";
const string sql = "SELECT IsNull(null)";
var odbcConnection = new OdbcConnection(connectionString);
odbcConnection.Open();
odbcConnection.Execute(sql); // Dapper
On my local machine it works fine, but in the container this crashes with an AccessViolationException. Here is the exception right from the container output:
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Interop+Odbc.SQLExecDirectW(System.Data.Odbc.OdbcStatementHandle, System.String, Int32)
at Interop+Odbc.SQLExecDirectW(System.Data.Odbc.OdbcStatementHandle, System.String, Int32)
at System.Data.Odbc.OdbcStatementHandle.ExecuteDirect(System.String)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(System.Data.CommandBehavior, System.String, Boolean, System.Object[], SQL_API)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(System.Data.CommandBehavior, System.String, Boolean)
at System.Data.Odbc.OdbcCommand.ExecuteNonQuery()
at Dapper.SqlMapper.ExecuteCommand(System.Data.IDbConnection, Dapper.CommandDefinition ByRef, System.Action`2<System.Data.IDbCommand,System.Object>)
at Dapper.SqlMapper.ExecuteImpl(System.Data.IDbConnection, Dapper.CommandDefinition ByRef)
at Dapper.SqlMapper.Execute(System.Data.IDbConnection, System.String, System.Object, System.Data.IDbTransaction, System.Nullable`1<Int32>, System.Nullable`1<System.Data.CommandType>)
I want to clarify that I am running hundreds of other queries just fine on the container, but it always fails when IsNull() is anywhere in the command text.
So I was curious and tried some other Microsoft Access functions, like Now() and IsNumeric(1030). Those also throw AccessViolationException!
I am really struggling with how to continue to resolve this problem. Why is the driver behaving differently? Doesn't the driver support Microsoft Access functions, or is there a dependency I need to add to get full Microsoft Access support?
Thanks
The reason I was getting the Access Violation is because I needed to install the Microsoft Access Runtime. Both the Access Database Engine and Microsoft Access Runtime are both required -- if only the database engine is installed connections to the MDB work but you cannot do anything fancy.
Now properly installing the Microsoft Access Runtime on a Docker container was no small feat. For that, there is a verbose answer to this question: How to install Access Runtime on a Docker container?
I want to add that I did not need any other dependencies to get this to work end-to-end. Not VC Runtime and not the .NET Framework.
Hope this helps somebody else in the future.
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.
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)?
I have an access 2000 application to manage. The DSN is pointing to the production Postgresql database and I'd like to point it to the one running on my machine for testing.
The problem is, I can't figure out how to change it. I tried running odbcad32.exe, and I did see the DSN and was able to change it to what I wanted (and it did pass the "test connection" test), but it still seems to be connecting to the old production dsn. I confirmed this by checking the connection logs that get dumped to C:\. I searched the registry for the production server's name; I could not find it (and I verified that my changes were getting posted to the registry. I searched the entire project's forms' sources for the server name, I could not find it there either.
Where else could Access be getting the dsn from?
Don't use DSNs. I much prefer DSN-Less connections as it is one less thing for someone to have to configure on each PC and one less thing for the users to screw up.
Using DSN-Less Connections
ODBC DSN-Less Connection Tutorial Part I
HOWTO: Use "DSN-Less" ODBC Connections with RDO and DAO
Carl Prothman's Connection String Home Page
Relink ODBC tables from code
Also it's easier to have a setup that uses a development connection string for you and a production connection string for everyone else. For example, assuming your users only get MDEs/ACCDEs, you could use the following function to determine which connection string to use
Public Function tt_IsThisAnMDE()
On Error GoTo tagError
Dim dbs As Database
Set dbs = CurrentDb
Dim strMDE As String
On Error Resume Next
strMDE = dbs.Properties("MDE")
If Err = 0 And strMDE = "T" Then
tt_IsThisAnMDE = True
Else
tt_IsThisAnMDE = False
End If
Exit Function
tagError:
Call LogError(Application.CurrentObjectName, "")
Exit Function
End Function
Apparently MS Access stores the whole connection string, not just DSN name. Here is what I see opening .mdb file in Notepad:
DSN=SQL-Northwind;APP=Microsoft Office 2003;WSID=DELLNOTEBOOK;DATABASE=Northwind;Network=DBMSSOCN;Address=LOCALHOST;Trusted_Connection=Yes
MS Access comes with Linked Table Manager however it won't update DSN once it's changed (at least not for me).
I guess your only choice is to delete a link and create a new one.
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")