Author |
Topic |
jhermiz
3564 Posts |
Posted - 2004-09-07 : 14:52:31
|
I do the following: <!-- #include file="dbconnect.asp" --> var conn = DBConnect(); var cmd = Server.CreateObject("ADODB.Command") Set cmd.ActiveConnection = comm cmd.CommandText = "select_user_exists" cmd.CommandType = adCmdStoredProc cmd.Parameters.Append cmd.CreateParameter("Login", adVarChar, _ adParamInput) cmd.Parameters.Append cmd.CreateParameter("Password", adVarChar, _ adParamInput) 'set values of parameters cmd("Login") = Request.Form("username") cmd("Password") = Request.Form("password") cmd.Execute cmd is a Command object that executes a stored procedure and may or may not return records (recordset). How do I assign a variable to hold these records from this cmd object?Can I doSet rs = cmd.Execute() ?Jonwww.web-impulse.comCan you dig it: http://www.thecenturoncompany.com/jhermiz/blog/ |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2004-09-07 : 15:27:01
|
Here's a sample from my VB6 dataobject. The same code should work in ASP 3.0 with the exception of the ADO contstant. 'init rs Set Rs = New ADODB.Recordset With Rs .CursorLocation = adUseClient .CursorType = adOpenStatic .LockType = adLockReadOnly End With 'init cmd Set Cmd = New ADODB.Command With Cmd .ActiveConnection = GetConnection() .CommandType = adCmdStoredProc .CommandText = "p_YourProc" End With Rs.Open Cmd Michael<Yoda>Use the Search page you must. Find the answer you will.</Yoda> |
 |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2004-09-07 : 15:28:36
|
BTW, this is in the ASP.net Forumn. Did you want a .Net solution to yor problem or an ASP 3.0 solution? Your code looks like 3.0 to me.Michael<Yoda>Use the Search page you must. Find the answer you will.</Yoda> |
 |
|
jhermiz
3564 Posts |
Posted - 2004-09-07 : 15:33:06
|
Its asp :( sorryJonwww.web-impulse.comCan you dig it: http://www.thecenturoncompany.com/jhermiz/blog/ |
 |
|
jhermiz
3564 Posts |
Posted - 2004-09-07 : 16:15:17
|
Hey mike I am having a bit of trouble here:Line 27 of some code I have:Set cmd = conn.ActiveConnectionkeeps giving me some error.The entire code is:<%@ Language=VBScript ENABLESESSIONSTATE=True %><%Option ExplicitDim strError, cmd, objRS, conn'see if the form has been submittedIf Request.Form("action")="login" Then 'the form has been submitted '// validate the form 'check if a username has been entered If Request.Form("username") = "" Then _ strError = strError & "- Please enter a username!<br>" & vbNewLine 'check if a password has been entered If Request.Form("password") = "" Then _ strError = strError & "- Please enter a password!<br>" & vbNewLine '// check if an error has occured If strError = "" Then 'continue 'include database connection code conn = DBConnect() cmd = Server.CreateObject("ADODB.Command") Set cmd.ActiveConnection = conn cmd.CommandText = "select_member_login" cmd.CommandType = adCmdStoredProc cmd.Parameters.Append cmd.CreateParameter("Login", adVarChar, _ adParamInput) cmd.Parameters.Append cmd.CreateParameter("Password", adVarChar, _ adParamInput) 'set values of parameters cmd("Login") = Request.Form("username") cmd("Password") = Request.Form("password") objRS = Server.CreateObject("ADODB.Recordset") Set objRS = cmd.Execute '// see if there are any records returned If objRS.EOF Then 'no username found strError = "- Invalid username or password!<br>" & vbNewLine Else 'username/password valid 'save session data Session("loggedin") = True Session("userid") = objRS("LoginID") Session("clientid") = objRS("ClientID") Session("login") = objRS("Login") Session("admin") = objRS("Admin") objRS.close() DBDisconnect(conn) 'redirect to ims page Response.Redirect ("default.asp") Response.End End If End If If strError <> "" Then 'output the error message 'add extra HTML... strError = "<p><font color=""#FF0000"">The following errors occured:" & _ "</font><br>" & vbNewLine & strError End If 'display message in URL.. (ie thank you for registering) If Request.QueryString("msg") <> "" And strError = "" Then strError = "<p>" & Request.QueryString("msg") & "</p>" End IfEnd IfSession("loggedin")=""Session("userid")=""Session("clientid") = ""Session("login") = ""Session("admin") = ""%> Not sure what is wrong with itThe error from the browser is :Error Type:Microsoft VBScript runtime (0x800A01B6)Object doesn't support this property or method: 'ActiveConnection'/login.asp, line 27Any help would be appreciated.Thanks,JonJonwww.web-impulse.comCan you dig it: http://www.thecenturoncompany.com/jhermiz/blog/ |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2004-09-07 : 16:30:51
|
you are using SET in the wrong place: conn = DBConnect() set cmd = Server.CreateObject("ADODB.Command") set cmd.ActiveConnection = conn What does DBConnect() return? A connection string or a connection object? if it's an object, you need to use SET in the first line as well.- Jeff |
 |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2004-09-07 : 16:35:13
|
^^^ What he said.Michael<Yoda>Use the Search page you must. Find the answer you will.</Yoda> |
 |
|
jhermiz
3564 Posts |
Posted - 2004-09-07 : 16:43:13
|
Err I saw that and fixed it after I posted but same error:Error Type:Microsoft OLE DB Provider for SQL Server (0x80040E4D)Login failed for user 'IMS'./login.asp, line 27Line 27 is:cmd.ActiveConnection = connThe dbconnect.asp contains:<SCRIPT LANGUAGE="JavaScript" RUNAT="server">//function connects to the IMS database.//returns a connection based object//PRE: none//POST: conn, a connection to the database//PARAM: nonefunction DBConnect(){ var conn = ""; try { var connString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=IMS;Password=ibm123;Initial Catalog=IMS;Data Source=HERCULES;"; conn = new ActiveXObject("ADODB.Connection"); conn.Open( connString ); } catch (e) { //catch any exceptions that might be thrown Response.write("Error:" + e.description + "<br/>"); } return conn; }//function disconnects from a database //if the state of the database is open//PRE: none//POST: integer return//PARAM: conn, connection object from invoking pagefunction DBDisconnect(conn){ if ((conn) != null) { if (conn.State == 1) {//connection open //close it conn.close(); } //set to null conn = null; } //non-zero = true return value return 1;}</SCRIPT> Am I mixing JS when I shouldnt be ?Jonwww.web-impulse.comCan you dig it: http://www.thecenturoncompany.com/jhermiz/blog/ |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2004-09-07 : 16:47:14
|
uh, that's not the same error. it's completely different. you are still getting an error, but now for a different reason.- Jeff |
 |
|
jhermiz
3564 Posts |
Posted - 2004-09-07 : 16:48:20
|
hmm but same line number you are right :(Jonwww.web-impulse.comCan you dig it: http://www.thecenturoncompany.com/jhermiz/blog/ |
 |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2004-09-07 : 16:48:33
|
I'm not sure that I'd mix things up like that, but it should work as written.The error you recived was an issue with the connection string.It says that user / pass doesn't work on the SQL server in question.Try to connect to that database with that user / pass and see what happens.Michael<Yoda>Use the Search page you must. Find the answer you will.</Yoda> |
 |
|
jhermiz
3564 Posts |
Posted - 2004-09-07 : 16:51:11
|
hmm worked fine when using query analyzer used:IMS as user nameibm123 as passwordJonwww.web-impulse.comCan you dig it: http://www.thecenturoncompany.com/jhermiz/blog/ |
 |
|
jhermiz
3564 Posts |
Posted - 2004-09-07 : 23:08:54
|
Anyone know why I am getting this error?I can log in to Q&AI just cant do it via the code for this asp page :(Frustrating Jonwww.web-impulse.comCan you dig it: http://www.thecenturoncompany.com/jhermiz/blog/ |
 |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2004-09-08 : 01:06:22
|
Have you taken a look inside teh client network utility on the webserver that this code is running on? It's possible that the default is set to named pipes. You might have to setup an alias that uses TCP to make this work properly.Something to try anyway. This is why I HATE ASP 3.0. When you run into problems like this is so friggin hard to debug vs asp.net. I'm several times more productive in .net than I am in 3.0 and I've been doing 3.0 for over five years!Michael<Yoda>Use the Search page you must. Find the answer you will.</Yoda> |
 |
|
jhermiz
3564 Posts |
Posted - 2004-09-08 : 09:00:48
|
Hmm...I'm just running this locally right now. I have IIS installed. Where is this client network utility?:( man I don't like ASP at all :(Jonwww.web-impulse.comCan you dig it: http://www.thecenturoncompany.com/jhermiz/blog/ |
 |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2004-09-08 : 11:28:36
|
Client network Utility is part of the SQL tools. Should be under Microsoft SQL Server in your programs folder in the start menu.Michael<Yoda>Use the Search page you must. Find the answer you will.</Yoda> |
 |
|
|