ASP shopping cart - asp-classic

Hello based on the example at http://www.15seconds.com/issue/010411.htm i will like to create an ASP shop but i would like to rewrite the connection to db as i don't have a dedicated server .
Instead of
Sub SubGetDSNCreateConn
strBasketDSN = Application("strBaskDSN")
set BaskConn = server.CreateObject ("ADODB.Connection")
BaskConn.ConnectionString = strBasketDSN
BaskConn.Open
End Sub
and
set SavedBaskConn = server.CreateObject ("adodb.connection")
SavedBaskConn.ConnectionString = Application("strBaskDSN")
SavedBaskConn.Open
i would like to use something like:
conn="provider=sqloledb;server=localhost;uid=username;pwd=password;database=shop"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strsql, conn
and i can't make it work .. does anybody could point me in the right direction or give me a better tutorial how to create a classic ASP shopping cart that could hold a big traffic?
Thank you

can i ask why you don't just change the settings in:
strBasketDSN = Application("strBaskDSN")
to match your requirement, rather than changing the code entirely?? I would be tempted to examine the contents of Application("strBaskDSN") and just change those to match your own database.
If i'm missing something obvious, then let me know.
jim

Related

UWP - Google Analytics - change trackingid at run time

I have and APP. Many customers use this APP.
I'd like to have an Google Trackingid for any Costumer.
Now i'd write my tracking id into my Analytics.xml
I use
xmlns="http://googleanalyticssdk.codeplex.com/ns/easytracker"
When in my code write
GoogleAnalytics.EasyTracker.GetTracker().SetCustomDimension(1, "Title")
GoogleAnalytics.EasyTracker.GetTracker().SetCustomDimension(2, "ID")
GoogleAnalytics.EasyTracker.GetTracker().SendView("Book")
I can't change TrackingId ...is possible to do this ?
Thanks
So, i had to change SDK
Now i use UWP.SDKforGoogleAnalytics.managed and i had wrote these rows
Dim _TrakerId As String = "UA-XXXX0-0"
Dim MyTraker As GoogleAnalytics.Tracker = GoogleAnalytics.AnalyticsManager.Current.CreateTracker(_TrakerId)
MyTraker.ScreenName = "Images"
Dim Hit = GoogleAnalytics.HitBuilder.CreateScreenView.Build
MyTraker.Send(Hit)
All work good... BUT... now i'd like to use Custom dimensions.
Can anyone hel me ??

(asp.net) my sql-code (update statement) works in database but not in program

I wrote a program to easily store/edit my comic book collection. I can add, delete and request anything (comic/character/team) by my update statement doesn't work. I made a copy in a query in my access database and that worked perfectly. The strangest thing is that my program doesn't give any errors, it completes the transaction but doesn't change the data in my database. (this is a problem on both comic, character and team updates).
Here is my code to update a comic.
Public Sub UpdateComic(comic As Comic)
Dim cn As New OleDbConnection(persistenceController.connectiestring)
Dim cmd As New OleDbCommand("UPDATE tblComics SET serie = #serie, volume = #volume, issue = #issue, release = #release, inpossession = #inpossession, timesread = #read, story = #story, Languages = #languages WHERE ID = #ID", cn)
cmd.Parameters.AddWithValue("serie", comic.Serie)
cmd.Parameters.AddWithValue("volume", comic.Volume)
cmd.Parameters.AddWithValue("issue", comic.Issue)
cmd.Parameters.AddWithValue("release", comic.Release)
cmd.Parameters.AddWithValue("inpossession", comic.InPossession)
cmd.Parameters.AddWithValue("read", comic.Read)
cmd.Parameters.AddWithValue("story", comic.story)
cmd.Parameters.AddWithValue("ID", comic.ID)
cmd.Parameters.AddWithValue("Languages", comic.Language)
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()
End Sub
Can anyone help me with this.
Thanks in advance.
Switch the position of the last two parameters added to the OleDbParameterCollection
cmd.Parameters.AddWithValue("Languages", comic.Language)
cmd.Parameters.AddWithValue("ID", comic.ID)
OleDb doesn't recognize the parameters by their name, but by their position. You should add the parameters in the exact order defined by the parameter placeholders in the command text
By the way. OleDb wants its placeholders parameter defined with the single question mark character (?), but MS-Access accepts also the syntax #name probably to have a better upgrade compatibility with its big cousin Sql Server.

Response.Redirect not working

I am not sure why this is not working.
I am verifying the logged on person has the correct security, if they do not I want to redirect them to another page.
If they do have the correct security the rest of the code on the page will continue to execute.
When I step through the code, it does execute the response.redirect, but the page continues to load.
strSQL = "Select * from tblSecurity Where SFID = '" & Right(My.User.Name, 4) & "' and (SecurityLevel = '900' or SecurityLevel = '850')"
ds = objData.SQLExecuteDataset(strSQL, CommandType.Text)
If ds.Tables(0).Rows.Count = 0 Then
Response.Redirect("~/NotAuthorized.aspx", False)
End If
That's exactly what you told it to do.
Passing false as the second parameter makes it not terminate the current page.
dont give the table value equal to zero...give the validation like ds.Tables(0).Rows.Count > 0... it means the table is holding the record if the given login details are right.
I tried all this and more ... and I only note my solution here for posterity and my own reference later. I ran into this problem while I had about 6 VS projects open, each in their own VS instance. Once I closed all but the one project down the problem went away. I am not sure what it was about the other project(s) that caused this particular problem but apparently VS doesn't like having too many of itself open.

Change ODBC-Connection in Access 2007

I hava a Pass-Through sql-query in access which queries my mysql-db.
My current ODBC connection for the query is defined as follows:
ODBC;UID=access_frontend; PWD=hello#world; DSN=my_db_test;
If I change my ODBC connection from my test to my normal DB
ODBC;UID=access_frontend; PWD=hello#world; DSN=my_db;
If I save my changes and restart again, Access has changed it back to my_db_test.
Is there any place where I can globally change my ODBC connection?`
I do not get this problem changing in code or manually. You can change the connection through VBA:
Dim qdf As QueryDef
''dbQSQLPassThrough = 112
For Each qdf In CurrentDb.QueryDefs
If qdf.Type = dbQSQLPassThrough Then
Debug.Print qdf.connect
qdf.connect = "ODBC;filedsn=z:\docs\test.dsn;"
Debug.Print qdf.connect
End If
Next
You will notice that the passthrough query illustrated refers to:
filedsn=z:\docs\test.dsn;
This is another easy way of changing the connection, just change the DSN, in the above case, you could just edit the file test.dsn.

What's wrong with this ASP recursive function?

When I call this function, everything works, as long as I don't try to recursively call the function again. In other words if I uncomment the line:
GetChilds rsData("AcctID"), intLevel + 1
Then the function breaks.
<%
Function GetChilds(ParentID, intLevel)
Set rsData= Server.CreateObject("ADODB.Recordset")
sSQL = "SELECT AcctID, ParentID FROM Accounts WHERE ParentID='" & ParentID &"'"
rsData.Open sSQL, conDB, adOpenKeyset, adLockOptimistic
If IsRSEmpty(rsData) Then
Response.Write("Empty")
Else
Do Until rsData.EOF
Response.Write rsData("AcctID") & "<br />"
'GetChilds rsData("AcctID"), intLevel + 1
rsData.MoveNext
Loop
End If
rsData.close: set rsData = nothing
End Function
Call GetChilds(1,0)
%>
*Edited after feedback
Thanks everyone,
Other than the usual error:
Error Type: (0x80020009) Exception occurred.
I wasn't sure what was causing the problems. I understand that is probably due to a couple of factors.
Not closing the connection and attempting to re-open the same connection.
To many concurrent connections to the database.
The database content is as follows:
AcctID | ParentID
1 Null
2 1
3 1
4 2
5 2
6 3
7 4
The idea is so that I can have a Master Account with Child Accounts, and those Child Accounts can have Child Accounts of their Own. Eventually there will be Another Master Account with a ParentID of Null that will have childs of its own. With that in mind, am I going about this the correct way?
Thanks for the quick responses.
Thanks everyone,
Other than the usual error:
Error Type: (0x80020009) Exception
occurred.
I wasn't sure what was causing the problems. I understand that is probably due to a couple of factors.
Not closing the connection and attempting to re-open the same connection.
To many concurrent connections to the database.
The database content is as follows:
AcctID | ParentID
1 Null
2 1
3 1
4 2
5 2
6 3
7 4
The idea is so that I can have a Master Account with Child Accounts, and those Child Accounts can have Child Accounts of their Own. Eventually there will be Another Master Account with a ParentID of Null that will have childs of its own. With that in mind, am I going about this the correct way?
Thanks for the quick responses.
Look like it fails because your connection is still busy serving the RecordSet from the previous call.
One option is to use a fresh connection for each call. The danger there is that you'll quickly run out of connections if you recurse too many times.
Another option is to read the contents of each RecordSet into a disconnected collection: (Dictionary, Array, etc) so you can close the connection right away. Then iterate over the disconnected collection.
If you're using SQL Server 2005 or later there's an even better option. You can use a CTE (common table expression) to write a recursive sql query. Then you can move everything to the database and you only need to execute one query.
Some other notes:
ID fields are normally ints, so you shouldn't encase them in ' characters in the sql string.
Finally, this code is probably okay because I doubt the user is allowed to input an id number directly. However, the dynamic sql technique used is very dangerous and should generally be avoided. Use query parameters instead to prevent sql injection.
I'm not too worried about not using intLevel for anything. Looking at the code this is obviously an early version, and intLevel can be used later to determine something like indentation or the class name used when styling an element.
Running out of SQL Connections?
You are dealing with so many layers there (Response.Write for the client, the ASP for the server, and the database) that its not surprising that there are problems.
Perhaps you can post some details about the error?
hard to tell without more description of how it breaks, but you are not using intLevel for anything.
How does it break?
My guess is that after a certain number of recursions you're probably getting a Stack Overflow (ironic) because you're not allocating too many RecordSets.
In each call you open a new connection to the database and you don't close it before opening a new one.
Not that this is actually a solution to the recursion issue, but it might be better for you to work out an SQL statement that returns all the information in a hierarchical format, rather than making recursive calls to your database.
Come to think of it though, it may be because you have too many concurrent db connections. You continually open, but aren't going to start closing until your pulling out of your recursive loop.
try declaring the variables as local using a DIM statement within the function definition:
Function GetChilds(ParentID, intLevel)
Dim rsData, sSQL
Set ...
Edit: Ok, I try to be more explicit.
My understanding is that since rsData is not declared by DIM, it is not a local variable, but a global var. Therefore, if you loop through the WHILE statement, you reach the .Eof of the inner-most rsData recordset. You return from the recursive function call, and the next step is again a rsData.MoveNext, which fails.
Please correct me if rsData is indeed local.
If you need recursion such as this I would personally put the recursion into a stored procedure and handle that processing on the database side in order to avoid opening multiple connections. If you are using mssql2005 look into something called Common Table Expressions (CTE), they make recursion easy. There are other ways to implement recursion with other RDBMS's.
Based on the sugestions I will atempt to move the query into a CTE (common table expression) when I find a good tutorial on how to do that. For now and as a quick and dirty fix, I have changed the code as follows:
Function GetChilds(ParentID, intLevel)
'Open my Database Connection and Query the current Parent ID
Set rsData= Server.CreateObject("ADODB.Recordset")
sSQL = "SELECT AcctID, ParentID FROM Accounts WHERE ParentID='" & ParentID &"'"
rsData.Open sSQL, conDB, adOpenKeyset, adLockOptimistic
'If the Record Set is not empty continue
If Not IsRSEmpty(rsData) Then
Dim myAccts()
ReDim myAccts(rsData.RecordCount)
Dim i
i = 0
Do Until rsData.EOF
Response.Write "Account ID: " & rsData("AcctID") & " ParentID: " & rsData("ParentID") & "<br />"
'Add the Childs of the current Parent ID to an array.
myAccts(i) = rsData("AcctID")
i = i + 1
rsData.MoveNext
Loop
'Close the SQL connection and get it ready for reopen. (I know not the best way but hey I am just learning this stuff)
rsData.close: set rsData = nothing
'For each Child found in the previous query, now lets get their childs.
For i = 0 To UBound(myAccts)
Call GetChilds(myAccts(i), intLevel + 1)
Next
End If
End Function
Call GetChilds(1,0)
I have working code with the same scenario.
I use a clientside cursor
...
rsData.CursorLocation = adUseClient
rsData.Open sSQL, conDB, adOpenKeyset, adLockOptimistic
rsData.ActiveConnectcion = Nothing
...
as pointed out in other responses, this is not very efficient, I use it only in an admin interface where the code is called infrequently and speed is not as critical.
I would not use such a recursive process in a regular web page.
Either rework the code to get all data in one call from the database, or make the call once and save it to a local array and save the array in an application variable.

Resources