Link to home
Start Free TrialLog in
Avatar of bleckron
bleckronFlag for United States of America

asked on

DSNless Connection String

I am attempting a DSNless connection to an Access Database.  Here is the connection string:
<%
var MM_NCIMHC2_STRING = strConnection = "DBQ=" & server.mappath("\CS\NCIMHC\Database\NCIMHC.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;UID=admin;"
%>
This resides on an ASP page in the connections folder and is called NCIMHC2.asp

The asp code to connect to the databse using the DSNless sting is as follows:
<!--#include virtual="/CS/Connections/NCIMHC2.asp" -->
<%
var Recordset1 = Server.CreateObject("ADODB.Recordset");
Recordset1.ActiveConnection = MM_NCIMHC2_STRING;
Recordset1.Source = "SELECT * FROM NCIMHC";
Recordset1.CursorType = 0;
Recordset1.CursorLocation = 2;
Recordset1.LockType = 1;
Recordset1.Open();
var Recordset1_numRows = 0;
%>

I get the following error:

Microsoft JScript runtime error '800a1391'

'server' is undefined

/CS/Connections/NCIMHC2.asp, line 2

I assume this has to do with the sever.mappath in the connection string but am unclear as to why.  I appreciate your wisdom and wil award accordingly.
Avatar of Colosseo
Colosseo
Flag of United Kingdom of Great Britain and Northern Ireland image

Hello

I could be wrong but does server not have to be uppercase ie Server

also this is not a valid string

var MM_NCIMHC2_STRING = strConnection = "DBQ=" & server.mappath("\CS\NCIMHC\Database\NCIMHC.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;UID=admin;"

Scott
actually it might be valid i think i read it wrong

sorry

Scott
Avatar of bleckron

ASKER

Ihave now changed the connection string to :

<%
var MM_NCIMHC2_STRING = "DBQ=" & Server.MapPath("\CS\NCIMHC\Database\NCIMHC.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;"
%>

And now get the following error:

ADODB.Recordset error '800a0bb9'

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

/CS/NCIMHC/Test.asp, line 5
A good reference for connection strings:

http://www.connectionstrings.com/

in particular

http://www.connectionstrings.com/?carrier=access

try that as an example

Scott
I tried the examples to no avail...
try doing a response.write on MM_NCIMHC2_STRING just to see what is getting set
I get a "0".  I t must not be getting to the databse.  The conection sstring must not be right somehow?
I figured it out:

<%
 FileName="Connection_ado_conn_string.htm"
 Type="ADO"
 DesigntimeType="ADO"
 HTTP="true"
 Catalog=""
 Schema=""
var MM_NCIMHC_STRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ Server.MapPath("/CS/NCIMHC/Database/NCIMHC.mdb")
%>

I am using Javascript so needed to use DSNless connectin with Javascript.
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial