Using Javascript to connect SQL Server database

∥☆過路亽.° 提交于 2019-12-06 16:04:29
Shadow The Princess Wizard

This is IE only code, and even in IE you have to explicitly allow such thing, see accepted answer here:
ActiveXObject in IE8

Your connectionstring is not escaped properly, it should be:

var connectionstring="Data Source=ИЛЬЯ-ПК;Initial Catalog=C:\\Program Files\\Microsoft SQL Server\\MSSQL10.MSSQLSERVER\\MSSQL\\DATA\\SIGMA_Database.mdf;User ID=Илья;Password=\"\";Provider=SQLOLEDB";

Have you tried

s.Open("SELECT Username FROM Users", connection);
rs.MoveFirst();
while(!rs.EOF)
{
   document.write(rs.Fields.Item(1));
   rs.MoveNext();
}

rs.Close();
connection.Close();

Edited rs.Fields

The problem with your codes is that you are accessing the SQL Server database using physical drive path C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\SIGMA_Database.mdf;

Connect to SQL Server using the following codes

var strconnectionstring = "Data Source=your_server_name;Initial Catalog=your_database_name;User ID=database_user_id;Password=database_password;Provider=SQLOLEDB";

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!