I am trying to make a button that writes something in a SQL database with a piece of javascript code. But i am constantly getting this error:
0x80040e21 Runtime-error JavaScript with an ole db action that contains multiple steps errors were occurred.
Here is my code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication9.WebForm1" %>
<!DOCTYPE html>
<html>
<head>
<title></title>
<script>
function myFunction() {
var connection = new ActiveXObject("ADODB.Connection");
var connectionstring = "Data Source=LP12;Initial Catalog=SmmsData;Integrated Security=True";
connection.Open(connectionstring);
var rs = new ActiveXObject("ADODB.Recordset");
rs.Open("INSERT INTO SysteemSensorInfo (SysteemNr,DrukSensor) VALUES (1,200)", connection);
rs.MoveFirst
while (!rs.eof) {
document.write(rs.fields(1));
rs.movenext;
}
rs.close;
connection.close;
}
</script>
</head>
<body>
<h1>A Web Page</h1>
<p id="demo">A Paragraph</p>
<button type="button" onclick="myFunction()">Try it</button>
</body>
</html>
The error seems to occur when it is reading the connecting string. The program breaks at this point: connection.Open(connectionstring). I have used this connection string a few times in C# code in other programs. So the mistake has to be something else.
Could you please help me?
User contributions licensed under CC BY-SA 3.0