MS SQL DATABASE CONNECTING TO CLASSIC ASP

  • Hi,

    This is my first project and Im connecting my MS SQL database with classic ASP. I got the connection string and its working, thats at least what i think because it was giving me a 500 internal server problem before but now its not. In fact its giving me a blank page. I was wondering if it really is working or not. I have a form to be filled in by the client, then the filled options to be saved in my db, and the result to display a success message that the request has been received.I want my form page to connect my db which is in different classic asp page and at the end I wnat it to gennerate a success message in another asp page.Im not getting it, all Im getting is that when I ask my form page to get the connection string I get a total blank page. Can anyone look at the code and tell me where am i making the mistake?

    the code is

    <add name="strConn" connectionString="Data Source=Name\SQLEXPRESS;Initial

    Catalog=my_database.mdf;Integrated Security=false;User ID=sa;Password=xxxxxxx"

    phoneNumber = request.QueryString("PhoneCode") + request.QueryString("text6")

    custName = request.QueryString("CustFname") +" "+ request.QueryString("CustLname")

    sql="Insert into suggestions (name, senderemail, telephone, mobile) values ('"& custName &"','" & request.QueryString("CustEmail") &"', )"

    conn.Execute(sql)

    conn.close

    set sql = Nothing

    'Set myMail=CreateObject("CDO.Message")

    'myMail.From="suggestions@testingserver.com"

    'myMail.To="test@testing.com"

    '//////////////////////////////////////////////////////////////////////

    if Mailer.SendMail then

    Response.Write "Mail sent..."

    else

    Response.Write "Mail send failure. Error was " & Mailer.Response

    end if

    response.Redirect("success2.asp")

    />

  • i realize this is probably a smippet, and not the whole page, but bear with me.

    I do not see the connectionstring being assigned to the connection object, nor do i see the Conn.Open.

    I did notice your command is open to SQL injection...you should use parameters instead.

    this is untested, quickly adapted from an old example, but it might help you get going:

    <%

    'ASP Script to Create two procedures if needed, then backup all tables definitions and table data to a pair of files.

    '=========================

    'Init A Connection

    '=========================

    dim Conn ' As Object

    set Conn = Server.Createobject("ADODB.Connection")

    Conn.ConnectionString = "PROVIDER=SQLOLEDB;DATA SOURCE=MyMachine\SQLEXPRESS;UID=sa;PWD=NotARealPassword;DATABASE=SandBox;"

    Conn.Open 'an error will occur here if the server/connection info is incorrect.

    '=========================

    'Init A Recordset

    '=========================

    Dim MyRs 'As ADODB.Recordset

    Set MyRs = Server.CreateObject("ADODB.Recordset")

    MyRs.CursorLocation = 3 'adUseClient

    '=========================

    'Check if we have a requeststring at all:

    '=========================

    If Request.QueryString = "" Then

    Response.Write "No variables provided: No items Added To Database, No Email Sent."

    Else

    'Do Our Processing

    phoneNumber = request.QueryString("PhoneCode") + request.QueryString("text6")

    custName = request.QueryString("CustFname") +" "+ request.QueryString("CustLname")

    CustEmail = request.QueryString("CustEmail")

    ' --note this is wide open to SQL injection:

    sql="Insert into suggestions (name, senderemail, telephone, mobile) values ('"& custName &"','" & CustEmail &"')"

    conn.Execute(sql)

    conn.close

    set sql = Nothing

    'Set myMail=CreateObject("CDO.Message")

    'myMail.From="suggestions@testingserver.com"

    'myMail.To="test@testing.com"

    '//////////////////////////////////////////////////////////////////////

    if Mailer.SendMail then

    Response.Write "Mail sent..."

    else

    Response.Write "Mail send failure. Error was " & Mailer.Response

    end if

    response.Redirect("success2.asp")

    End If

    %>

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • First of all I want to Thank you for your quick reply.and yes this is not the whole page code.

    I did try the string you sent me but I got the following error.

    Internal Server Error

    The server encountered an internal error or misconfiguration and was unable to complete your request.

    Please contact the server administrator to inform of the time the error occurred and of anything you might have done that may have caused the error.

    More information about this error may be available in the server error log.

    This is the same error which Im getting while trying most of the strings and its really making me tired. Could you please help me in it.

  • 1

  • I'm not a Web Developer, so I can't comment on the rest of the code, but I did spot a potential problem in your connection string:-

    Initial Catalog=my_database.mdf

    You should be referring to the name of the database, not the database file

  • what is the difference between the "database name" and the database file? shouldnt it be the same??

  • the section you pasted looks like it came from a .net config file. i think you're having trouble directly related to that....are you doing ASP classic or ASP.NET?

    the connection string i pasted is a working example...i'd go with that and substitute the values.

    typically a database file might be an access database or a flat file .... a database is a service that responds

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • IM working in classic ASP and Im very new to the whole enviroment, both MS SQL and classic ASP. Im testing different strings to check out which is working for me.My origional DB was in access but we had to change ourservice provoider i.e; the host so we had to shift to MS SQL. I was getting a 500 internal server side error with different strings but te one i posted was for which I got a total blank white page, no 500 error.

    So, its been day now that Im trying to work it out , browsing , googling and doing every possible thing i can but nothing seem to work. 🙁

  • well... start with the basics....if you want real help, you'll have to give real details.show us the exact code you are using.

    comment out 99% fo the code , run the page, then uncomment out code one line at a time. run the page.

    add a lot of <% Response.Write "About to execute Code X"%> in your code so you know at which point the code executed vs where it failed.

    if this code snippet you pasted is really in your file, it would cause the page to fail it is not in the correct syntax at all.:

    <add name="strConn" connectionString="Data Source=Name\SQLEXPRESS;Initial

    Catalog=my_database.mdf;Integrated Security=false;User ID=sa;Password=xxxxxxx"

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • I have sent you the code. Could you please check that.

    Regards.

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply