I have some routine task (change some column types in MSSQL) on multiple server. So, I'm trying to make a script program that connects to MSSQL and change structure of some tables.
What I've done so far... I made a text file on Desktop and wrote the code below in the file
<!DOCTYPE html>
<html>
<head>
<script>
var objConnection = new ActiveXObject("adodb.connection");
var strConn = "driver={sql server};server=192.168.139.121;database=mytest;uid=testuser;password=testpw";
objConnection.Open(strConn);
var rs = new ActiveXObject("ADODB.Recordset");
(queries for changing table structure)..
</script>
</head>
<body>
</body>
After that, I saved it as HTML file and executed it with Internet Explorer. But, No response.. I found that after executing 'objConnection.Open(strConn);' IE waits for response forever.. Is there any library or program to be installed to execute all the code above? please give me some hints
You can try this (Works only in IE
) :
<!DOCTYPE html>
<html>
<head>
<script>
var connection = new ActiveXObject("ADODB.Connection") ;
var connectionstring="Data Source=<server>;Initial Catalog=<catalog>;User ID=<user>;Password=<password>;Provider=SQLOLEDB";
connection.Open(connectionstring);
//your queries here
rs.close;
connection.close;
</script>
</head>
<body>
</body>
</html>
You really shouldn´t use client side script like javascript to access databases for several reasons like bad practice, security issues etc. You can use .Net, PHP, JAVA etc which are server side language and better way to use these to interact with the databases.