hi friends,
can any one out here help me by giving me the code to connect to an MSACCESS database using javascript.
17 120773
it would be a task to do such a thing seeming how the database isn't going to be on every users computer, javascript is client side, you would need a serverside script to do this for you, ASP and PHP can both efficiently do this.
hi friends,
can any one out here help me by giving me the code to connect to an MSACCESS database using ASP(javascript)
I am also interesting in using JS to access an MS-Access file. I know this is CLIENT SIDE. The access file will be locally hosted so JS seems the way to go.
I am very new to JS, but looking use it to aid in IE pages that will be dynamically created from a DVD that is distributed (not from the web).
The only snip-it that I am starting to review is as follows:
<% @LANGUAGE="JScript" %>
var strConnect = "DSN=YourDSNHere";
oConn=Server.CreateObject("ADODB.Connection");
oConn.Open(strConnect);
var strSQL = "SELECT SomeField FROM myTable;";
var rsAd=oConn.Execute(strSQL);
Response.Write("First row is, "+ rsAd.Fields("SomeField") )
oConn.Close();
hi friends,
can any one out here help me by giving me the code to connect to an MSACCESS database using javascript.
If you are using asp.net, there is no way to connect to database using standard javascript. You have to install server side javascript and you can do data connection with any data souce and delete,modify,view the records of the table.
That is the only way.Bye
Sanju John
You can connect to database from client-side script, if MDAC is installed on client's computer.
Just Update strConn with the correct Data Source, and SQL query as desired. -
<html>
-
<head>
-
<title>Entitled Document</title>
-
<script language="JavaScript">
-
function getCount(){
-
var cn = new ActiveXObject("ADODB.Connection");
-
var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\clientDB.mdb;Persist Security Info=False";
-
cn.Open(strConn);
-
var rs = new ActiveXObject("ADODB.Recordset");
-
var SQL = "select count(*) from Customers";
-
rs.Open(SQL, cn);
-
alert(rs(0));
-
rs.Close();
-
cn.Close();
-
-
}
-
</script>
-
</head>
-
<body>
-
<input type="button" value="Get count" onclick="getCount()">
-
</body>
-
</html>
-
-
Did it help?
Hi, thanks for posting this solution! I'm working on a local application which uses a local DB as well, so this is a great snip.
I do have a question about extending this. My DB is not Access and uses an ActiveX DLL for communication, but I've never worked with ActiveX in this manner. Would you happen to know how to modify this script to work with an ActiveX COM object?
I'm guessing it would be something like this to start, but obviously I'm clueless, so please correct as necessary.
6.
var cn = new ActiveXObject("ActiveXDB.com");
but then I'm clueless as to how to open a connection, send data to it or get the data back?
Sorry if this is a newbie question, but I've been searching for a day now and most answers I find are just "No, Javascript has no business talking to a database". If this method works out, it would be an awesome decrease in system requirements for my application, so I very much appreciate any help available.
Thanks!
D
Yes it should work.
I suppose that know the methods of your DLL, then just follow the previous ADODB sample and update it as needed.
Please note that only IExplorer allows ActiveX objects, and FireFox, Opera... do not allow.
Blarg, getting "Automation server can't create object" when running with an ActiveX friendly platform (HTA for testing purposes). Can anyone see what I'm doing wrong here that causes the error?
SQLiteDb.DLL is registered on the machine, I even took the classID out of the registry to make sure it was right.Thanks for any help! - <html>
-
<head>
-
<object>
-
id = "SQLiteDb"
-
CLASSID = "CLSID:1B562564-1BB6-4970-B0FB-31B24AA9C1D0"
-
</object>
-
-
<script language="JavaScript">
-
-
var cn = new ActiveXObject("SQLiteDb.Connection");
-
var strConn = "Database=db/test.db";
-
</script>
-
-
</head>
-
<body>
-
-
<script language="javascript">
-
function getdata(){
-
cn.Open(strConn);
-
var rs = new ActiveXObject("SQLiteDb.Recordset");
-
var SQL = "SELECT CoName from Companies WHERE CoID=1";
-
rs.Open(SQL, cn);
-
alert(rs(0));
-
rs.Close();
-
cn.Close();
-
}
-
</script>
-
<input type="button" value="Get data"
-
onclick="getdata()">
-
</body>
Run this code and see if connection is created: - <html>
-
<head>
-
-
<script language="JavaScript">
-
-
var cn = new ActiveXObject("SQLiteDb.Connection");
-
if (typeof(cn)=="undefined" || cn==null)
-
alert("Unable to create the connection object!");
-
else
-
alert("Connection object was successfully created!");
-
-
var strConn = "Database=db/test.db";
-
function getdata(){
-
cn.Open(strConn);
-
var rs = new ActiveXObject("SQLiteDb.Recordset");
-
var SQL = "SELECT CoName from Companies WHERE CoID=1";
-
rs.Open(SQL, cn);
-
alert(rs(0));
-
rs.Close();
-
cn.Close();
-
}
-
</script>
-
-
</head>
-
<body>
-
-
<input type="button" value="Get data"
-
onclick="getdata()">
-
</body>
-
</html>
Run this code and see if connection is created: - <html>
-
<head>
-
-
<script language="JavaScript">
-
-
var cn = new ActiveXObject("SQLiteDb.Connection");
-
if (typeof(cn)=="undefined" || cn==null)
-
alert("Unable to create the connection object!");
-
else
-
alert("Connection object was successfully created!");
-
-
var strConn = "Database=db/test.db";
-
function getdata(){
-
cn.Open(strConn);
-
var rs = new ActiveXObject("SQLiteDb.Recordset");
-
var SQL = "SELECT CoName from Companies WHERE CoID=1";
-
rs.Open(SQL, cn);
-
alert(rs(0));
-
rs.Close();
-
cn.Close();
-
}
-
</script>
-
-
</head>
-
<body>
-
-
<input type="button" value="Get data"
-
onclick="getdata()">
-
</body>
-
</html>
Hi, thanks for the help! And the survey says... Nope! Still has the "Automation Server" error. Interesting that I didn't need to put in the Object CLSID? I thought it was necessary for the registry to look up this object?
Anyways, this has got to be about creating and using the ActiveX object. I've posted on the manufacturer forums and gotten no helpful responses, but this code was in their help: -
Dim cn As SQLiteDb.Connection
-
Set cn = New SQLiteDb.Connection
-
-
cn.ConnectionString = "Data Source=C:\MyData\MyDatabase.db;"
-
cn.Open
-
So if this is supposed to work in VBscript, I can't see why the Javascript doesn't work, unless it has something to do with the "As SQLiteDb.Connection" line?
I have a different setup to the same DB with an ODBC driver and using an ADODB connection object, and it works fine. Unfortunately, that won't work for the distribution because it still requires installation of the driver and ADO to be installed on the client machine.
So, is there an ActiveX forum that I should move over to for this? Or are we ok to keep working here?
Thanks again for the help!
I guess that your ActiveX does not expose a COM interface for any application.
Perhaps it's a VB6 DLL that works in VB only (maybe .Net too).
At this point just the manufacturer should offer more support.
God bless you,
Dorin.
Thanks for all of your help Dorin. At least I'm up and running with the ODBC method in Javascript, so I'm not at a total work stoppage :)
I agree about the manufacturer. They advertise that this is usable by any COM-aware language, including VBscript like the example I posted, but they surely ought to give full information on using it as a web object. I don't know how to make this work only because every other ActiveX object I've ever used has come with a code snippet from the manufacturer, and all I did was paste that in and get to work with it.
So, guess I'll keep looking for a solution instead of buying theirs. Too bad, theirs supported ADO-style requests, and that would let me use a lot of standard methods to get the job done quicker.
Thanks again for your help, you've been great!
Dorin,
Thank you for your post; it helped me alot.
Bobby
You can connect to database from client-side script, if MDAC is installed on client's computer.
Just Update strConn with the correct Data Source, and SQL query as desired. -
<html>
-
<head>
-
<title>Entitled Document</title>
-
<script language="JavaScript">
-
function getCount(){
-
var cn = new ActiveXObject("ADODB.Connection");
-
var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\clientDB.mdb;Persist Security Info=False";
-
cn.Open(strConn);
-
var rs = new ActiveXObject("ADODB.Recordset");
-
var SQL = "select count(*) from Customers";
-
rs.Open(SQL, cn);
-
alert(rs(0));
-
rs.Close();
-
cn.Close();
-
-
}
-
</script>
-
</head>
-
<body>
-
<input type="button" value="Get count" onclick="getCount()">
-
</body>
-
</html>
-
-
Did it help?
Hi Dorin,
Thanks a lot for this post. It helped me in my application.
One thing I am still searching is that the data is retrieved if SQL is pointing to a table and not a query object which has some functions called.
Thanks anyways
regards
mustang123
You can connect to database from client-side script, if MDAC is installed on client's computer.
Just Update strConn with the correct Data Source, and SQL query as desired. -
<html>
-
<head>
-
<title>Entitled Document</title>
-
<script language="JavaScript">
-
function getCount(){
-
var cn = new ActiveXObject("ADODB.Connection");
-
var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\clientDB.mdb;Persist Security Info=False";
-
cn.Open(strConn);
-
var rs = new ActiveXObject("ADODB.Recordset");
-
var SQL = "select count(*) from Customers";
-
rs.Open(SQL, cn);
-
alert(rs(0));
-
rs.Close();
-
cn.Close();
-
-
}
-
</script>
-
</head>
-
<body>
-
<input type="button" value="Get count" onclick="getCount()">
-
</body>
-
</html>
Did it help?
See this link. -
...
-
rs.Open("yourTableName",cn, 1, 1, 2);
-
...
-
Be blessed.
I found a JavaScript library that allows you to execute SQL queries in a single command with the option of selecting the output format of the result-set from choices including JSON, XML, and HTML.
The library is called ACCESSdb and you can get it here: http://www.accessdb.org/ Sign in to post your reply or Sign up for a free account.
Similar topics
by: Pato Secruza |
last post by:
Hi everyone!
I have a really frustrating error and need help.
I’m trying to do a function that gets the properties and names
of the fields in a MS Access database using ASP. I haven’t...
|
by: mahipalerasani |
last post by:
I am trying to connect to the Access database for querying, inserting and updating the data using 'C' API's.
If somebody has code to connect to Access Database using C API's can you you please...
|
by: srivijayaragavan |
last post by:
Can any one help me how to connect MS Access from Javascript with example?
Is any component required or that is to be installed in client side?
I have read that some component needs to be installed.
|
by: Sunlis |
last post by:
I need to find a way to communicate with a MS Access database using Javascript, PHP, or some other client-side scripting.
It's for a Computer Science exam, and I cannot solve this problem.
Users...
|
by: Abhi~Menon |
last post by:
I've a situation here where i want to interact with the local Access Database from an HTML page. I've created a DSN for the Access. I'm wondering how the connection part has to made from Java Script....
|
by: asad56 |
last post by:
I am workin with a superstore managment project. I connect Access database with main form . Then it work properly. But now I connect same database with another table or field in another form which is...
|
by: lintolawrance |
last post by:
hi friends,
can any one out here help me by giving me the code to connect to an SOL database using javascript.
|
by: mkhizess |
last post by:
Hi Buddzy
Can you plz help to connect to Access DataBase input from HTML form using insert statement. I am still new on programming with html here is my code .
<html>
<head>
...
|
by: 9815402440 |
last post by:
hi
i have a ms access database which is on web server (ftp://www.abc.com) .
i want to connect this database using ado in vb6.
please help
regards
manpreet singh dhillon hoshiarpur
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
|
by: Johno34 |
last post by:
I have this click event on my form. It speaks to a Datasheet Subform
Private Sub Command260_Click()
Dim r As DAO.Recordset
Set r = Form_frmABCD.Form.RecordsetClone
r.MoveFirst
Do
If...
|
by: ezappsrUS |
last post by:
Hi,
I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
| |