Why do people do these things in ASP ?

Results 1 to 5 of 5

Thread: Why do people do these things in ASP ?

  1. #1
    Johnathan Guest

    Default Why do people do these things in ASP ?

    HI ALL,<BR>While reviewing the script of others, I notice that <BR>people connect to the database by first creating a session. like this:<BR>&#060;% <BR>Session("DatabasePath") = "D:Websaccountnamedataaccessdatabase.mdb"<BR><BR>S et DataConnection = Server.CreateObject("ADODB.Connection")<BR>DataCon nection.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ="D:Websaccountnamedataaccessdatabase. mdb";"<BR>%&#062;<BR>Why do they do this, ? It appears to me that if Sessions are in fact to be avoided they should just include the path right in the statement like this ? <BR>DataConnection.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Session("DatabasePath") & ";"<BR>AM I RIGHT ? Or is there a secret reason why people put the path in a session variable. Does it make for better programming some how ? <BR><BR>QUESTION NUMBER 2<BR>I notice some people love to do this <BR>sqlstr="Select fields FROM table1 Where"<BR>sqlstr=sqlstr & "field1=xyz"<BR>sqlstr=sqlstr & "And field2=abc"<BR>Why do people break up their sql statements in this fashion instead of just writing out the long 1 line statement ? <BR>I just wanted to know if it made sense in terms of better programming or so .<BR>Sincerely<BR>Johnathan

  2. #2
    Jason Miller Guest

    Default RE: Why do people do these things in ASP ?

    1) Actually, I have a function I can call (connectDB) which generates a db connection and sets a global var (connected) to true, such that "if not connnected then connectDB()". I also have a "if connected then disconnectDB()" at the end of every page, if not earlier.<BR><BR>2) It improves readability for some people. Me, I say you should turn them into functions which return recordsets so you don&#039t have to deal with it all of the time. ie:<BR>set myRS = viewRecords("table_xyz", "col1, col2, col3", "col1 = &#039BOB&#039 order by col3 desc")<BR><BR>But that&#039s just me.

  3. #3
    Join Date
    Dec 1969

    Default RE: Why do people do these things in ASP ?

    To answer your first question, some people do this because Visual InterDev 1.0 did this when adding a database to a web project. Doing this method is pure evil, and should be avoided at all costs. For a good article on why, check out:<BR>http://www.learnasp.com/learn/globalproblems.asp<BR><BR>For your second question, breaking up a lengthy string makes it easy to read. Of course, it is less efficient than using one long string, but the time saved is minimal (unless you are doing a number of concatenations inside of a tight loop).<BR><BR>Happy Programming!<BR><BR>(Note, for a good PowerPoint presenation on good ASP techniques, check out: http://support.microsoft.com/support/activeserver/AspBestPractices.ppt)

  4. #4
    Thomas Whalen Guest

    Default RE: Why do people do these things in ASP ?

    Yes, breaking up the SQL statements makes for better programming. Having one long SQL string and building an SQL string with each part of the string on a separate line are two different things, in terms of syntax. But, they both do the same thing. <BR><BR>So, what is the advantage of building an SQL string (or any type of string for that matter)? It is easier to understand the code, and to debug the code. If you think about it, the brain understands things better when what is sees is linear or organized, rather than one big jumbo of a mess. <BR><BR>So, the next question is: does it make any difference performance wise? Some say yes, because that means more lines for the browser to have to read. Others say no, because the browser ignores blank space. So, adding extra variable names to build an SQL string MIGHT make a negative impact, performance wise. But, I doubt anyone would even come close to noticing the difference. <BR><BR>The last question is: why does this bother YOU? There are some programmers out there who think that creating scrambled-eggs code or "spaghetti code" makes them nerdier or smarter, or should give them job security (because no one else can understand their code). Well, that has all changed. The average programming evironment today involves more than one programmer. If the other guy can&#039t understand your code, then that means you didn&#039t do your job right. What do I mean by that? The programmer&#039s job today, in this high-production atmosphere, is to create clear, precise, well-documented code, so that the job of programming actually becomes easier, less stressful, cheaper from the employers&#039 stand point of view, and easier for the next guy (should you leave the company) to pick up where you left off, instead of having to spend hours, days or weeks trying to figure out what you were trying to do.<BR><BR>Again, do you think it is better to create code that doesn&#039t make sense (it works, but looks really complicated), or do you think it is better to create code that is simpler to debug, to build onto or manipulate, and is easier for others to understand?<BR><BR>Cheers,<BR><BR>Thomas Whalen<BR>(605)332-2457<BR>harrison2@dtgnet.com<BR>Web Developer

  5. #5
    Join Date
    Dec 1969

    Default RE: Why do people do these things in ASP ?

    using the "strSQL" concatenator makes it easier to find syntax errors in the SQL statement...imagine one SQL statement 200+ characters in length, and it has ONE syntax error somewhere in it!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts