Connect to SQL Server with JS
I stumbled across a post on here regarding connecting to a DB with JavaScript.
How to connect to SQL Server database from JavaScript in the browser?
I'm building a gadget for windows vista/7 that will work with My Movies, a movie management app for Media Centre. The My Movies app uses SQL Server 2005 Express for its DB, and the only option I have for DB connectivity is JavaScript as gadgets do not (to my knowledge) support server side scripting languages.
var connection = new ActiveXObject("ADODB.Connection") ;
var connectionstring="Data Source=WKS-MER03308;Initial Catalog=MYMOVIES;User ID=mymovies;Password=7eBrABud;Provider=SQLOLEDB";
connection.Open(connectionstring);
var rs = new ActiveXObject("ADO开发者_StackOverflow中文版DB.Recordset");
rs.Open("SELECT nvcLocalTitle FROM tblTitles", connection);
rs.MoveFirst
while(!rs.eof)
{
document.write(rs.fields(1));
rs.movenext;
}
rs.close;
connection.close;
I've tried running this and I continue getting the error:
Message: Login failed for user 'mymovies'. (Unfortunately I can't access the logs to see the state and get an accurate reason for the failure)
On the my movies website it gives the following details for connecting to the db.
Server=[Server]\MYMOVIES
Database=My Movies
User ID=mymovies
Password=7eBrABud
Trusted_Connection=False
Any ideas what I am doing wrong?
You've got the instance and database name confused. Try the following:
var connectionstring="Data Source=WKS-MER03308\MYMOVIES;Initial Catalog=MY MOVIES;
User ID=mymovies;Password=7eBrABud;Provider=SQLOLEDB";
精彩评论