Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Jscript connection string help 1

Status
Not open for further replies.

biry

Technical User
Nov 5, 2004
127
CA
Hi, i not too familkiar with JScript and an getting this error of Expected ";"
at this part:
connobj.open "DRIVER={SQL
------------^

any thoughts on this?
Code:
connobj.open "DRIVER={SQL Server};SERVER=localhost;DATABASE=DBNAME;UID="+ Application("ipo_admin")+";PWD=" + Application("ipo_admin_password") +";";

	rsobj = Server.createobject ("ADODB.recordset");
	rsobj.open(sql, connobj);

thanks
 
Javascript, being client-side, is unable to interact with databases. Is this server-side?

--Chessbot

There is a level of Hell reserved for probability theorists in which every monkey that types on a typewriter produces a Shakespearean sonnet.
 
while I know negative zero about client-side js, if it even exists, my first suggestion would be to add parentheseseseseseses.

Code:
connobj.open("DRIVER={SQL Server};SERVER=localhost;DATABASE=DBNAME;UID="+ Application("ipo_admin")+";PWD=" + Application("ipo_admin_password") +";");

*cLFlaVA
----------------------------
[tt]insert funny quotation here.[/tt]
 
the code works with a dsn connection but i wanted to change it to dsnless this is the page:
page which combines ASP and JScript, its the db connection with the problem in the first post:
Code:
<%@ Language=JavaScript%>
<%//response.buffer=false%>
<script language='vbscript' runat='server'>

<%
	var table = String(Request.QueryString("t"));
	var sortby = String(Request.QueryString("s"));
	var dir = String(Request.QueryString("d"));
	var cc = String(Request.QueryString("c"));

	if (table == "undefined") table = "sec10K";
	if (sortby == "undefined") sortby = "date_filed";

	if ((cc != sortby) || (dir == "undefined")) {
		if (sortby == "date_filed")
			dir = "desc";
		else
			dir = "asc";
	}

	var countSQL;

	if (cc == "undefined") cc = sortby;

	if (table == "sec45"){
		var sql = "select * from secfilings where form_type='4a' or " +
				"form_type='4' or form_type='5' order by " + sortby + " " + dir;
		countSQL = "select count(*) as count from secfilings where form_type='4a' or form_type='4' or form_type='5'";
	}else {
		countSQL = "select count(*) as count from " + table;
		var sql = "select * from " + table + " order by " + sortby + " " + dir;
	}

	if (sortby == "date_filed") {
		sql += ", company_name ";
		if (dir == "asc") {
			sql += "desc";
		} else {
			sql += "asc";
		}
	}


//'Database Connection

	if ( ! (connobj = Server.CreateObject("ADODB.Connection")) )
		Response.write("Connection failed");

connobj.open "DRIVER={SQL Server};SERVER=localhost;DATABASE=DBNAME;UID="+ Application("ipo_admin")+";PWD=" + Application("ipo_admin_password") +";";

	rsobj = Server.createobject ("ADODB.recordset");
	rsobj.open(sql, connobj);

	var od = dir == "asc" ? "desc" : "asc";

    var countRS = Server.createobject("ADODB.recordset");
    countRS.open(countSQL, connobj);

    var count = countRS("count");
%>
 
tgreer, his code is not mixed up at all. There is no rule that you must use server side VBScript when you code in ASP, however most of the documentation you'll find will be written in VBScript. Additionally, in the title of this thread he specified it was a JScript question (which implies server side javascript). Furthermore, since there is no "JScript" forum on tek-tips I don't feel that his question is completely out of place here. However, I do agree that it is probably better asked in the ASP forum, even though most of the users there only ask questions / give answers in VBScript.

Now, to move on to your question biry, I use JScript for all my ASP that I do. Here is the connection variables that I use to connect to an SQL Server database (taking out all the sensitive information as I'm sure you can understand):

Code:
var strConn = "Provider=SQLOLEDB;Data Source=" + serverName + ";Initial Catalog=" + databaseName + ";User Id=" + userID + ";Password=" + pwd;
var oConn   = Server.CreateObject("ADODB.Connection");
var oRS   = Server.CreateObject("ADODB.Recordset");

oConn.ConnectionString = strConn;
oConn.CursorLocation = 3;
oConn.Mode = 3;
oConn.Open();

oRS.ActiveConnection = oConn;
oRS.CursorType = 3;
oRS.LockType = 3;
oRS.CursorLocation = 3;
then to perform a query on the database you would do something like:
Code:
oRS.Source = "SELECT BLAH FROM DATABASEBLAH WHERE BLAHBLAHBLAH";
oRS.Open();
var result = oRS.Fields("BLAH").value;
oRS.Close();
//and since JScript has no equivalent to VBScript's "nothing" we can't destroy the connection
//(well.... not entirely true, but that's what you asked anyway)

-kaht

banghead.gif
 
kaht, thanks very much, and your explination of my question hit the "head on the nail", i would post it in a asp forum but i'm native of asp and can implement this connection both dsn and dsnless in asp, as i think most can in the asp forum, while playing Tron and baking 30 brownies in twenty but JScript is a story i'm not use too, as i think most can in the asp forum, and your right there is no Jscript forum here (weird) I didn't post it in the asp forum cause i thought people there would say things like, why do you have a ";" at the end of oRS.Open();

thanks for the help, i much appreciated it!!
 
nail on the head.

:)

*cLFlaVA
----------------------------
[tt]insert funny quotation here.[/tt]
 
why can't it be about hitting the "head" aspect of the nail

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top