Results 1 to 19 of 19

Thread: ASP & SQL Writing (Microsoft SQL Server 2008)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Posts
    109

    Exclamation ASP & SQL Writing (Microsoft SQL Server 2008)

    Hello,

    How can I insert the First Name & Last Name TextBox Data into the database?

    Code:
    <html>
    
    <head>
    
    <title>New Member - OBMFO</title>
    
    </head>
    
    <body>
    
    Your first name is 
    
    <&#37;
    FirstName = request("firstname")
    response.write FirstName + " "
    
    LastName = request("lastname")
    response.write LastName 
    %>
    
    <%
    ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Registration;Data Source=KAWSERHOSSAIN\SQLEXPRESS"
    SQL = "INSERT INTO [Registration Table] (First) VALUES ('Hello World')" 
    %>
    
    </body>
    
    </html>
    Please HELP Thanks
    Last edited by Kawser; Feb 3rd, 2011 at 01:18 AM.

  2. #2
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: ASP & SQL Writing (Microsoft SQL Server 2008)

    This should get you pretty close
    Code:
    <html>
    
    <head>
    
    <title>New Member - OBMFO</title>
    
    </head>
    
    <body>
    
    Your first name is 
    
    <&#37;
    FirstName = request("firstname")
    response.write FirstName + " "
    
    LastName = request("lastname")
    response.write LastName 
    
    ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Registration;Data Source=KAWSERHOSSAIN\SQLEXPRESS"
    SQL = "INSERT INTO [Registration Table] (First, Last) VALUES ('" & FirstName "', '" & LastName & "')"
    Set Cn = Server.CreateObject("ADODB.Connection")
    Cn.Open
    Cn.Execute SQL
    Cn.Close
    Set Cn = Nothing
    %>
    
    </body>
    
    </html>

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Posts
    109

    Re: ASP & SQL Writing (Microsoft SQL Server 2008)

    Quote Originally Posted by MarkT View Post
    This should get you pretty close
    Code:
    <html>
    
    <head>
    
    <title>New Member - OBMFO</title>
    
    </head>
    
    <body>
    
    Your first name is 
    
    <%
    FirstName = request("firstname")
    response.write FirstName + " "
    
    LastName = request("lastname")
    response.write LastName 
    
    ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Registration;Data Source=KAWSERHOSSAIN\SQLEXPRESS"
    SQL = "INSERT INTO [Registration Table] (First, Last) VALUES ('" & FirstName "', '" & LastName & "')"
    Set Cn = Server.CreateObject("ADODB.Connection")
    Cn.Open
    Cn.Execute SQL
    Cn.Close
    Set Cn = Nothing
    %>
    
    </body>
    
    </html>
    Thank you so much for you help MarkT,

    BUT

    I get this error:

    "An error occurred on the server when processing the URL. Please contact the system administrator.

    If you are the system administrator please click here to find out more about this error."

  4. #4
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: ASP & SQL Writing (Microsoft SQL Server 2008)

    It looks like I may have missed an ampersand. Try using this line instead.

    SQL = "INSERT INTO [Registration Table] (First, Last) VALUES ('" & FirstName & "', '" & LastName & "')"

    Also make sure the field names you are inserting into are correct.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Posts
    109

    Re: ASP & SQL Writing (Microsoft SQL Server 2008)

    Quote Originally Posted by MarkT View Post
    It looks like I may have missed an ampersand. Try using this line instead.

    SQL = "INSERT INTO [Registration Table] (First, Last) VALUES ('" & FirstName & "', '" & LastName & "')"
    MarkT

    Yes I noticed that and fixed it, but I still get the error

    Thanks.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Posts
    109

    Re: ASP & SQL Writing (Microsoft SQL Server 2008)

    MarkT,

    I have a better error msg

    "Microsoft OLE DB Provider for ODBC Drivers error '80004005'

    [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

    /Admin/NewMember.asp, line 23 "

    Thanks Again.

  7. #7
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: ASP & SQL Writing (Microsoft SQL Server 2008)

    All I can recommend is you comment out all the script lines and try loading the page. Then uncomment the lines one at a time until you find the line that is causing the problem.

  8. #8
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: ASP & SQL Writing (Microsoft SQL Server 2008)

    Quote Originally Posted by Kawser View Post
    MarkT,

    I have a better error msg

    "Microsoft OLE DB Provider for ODBC Drivers error '80004005'

    [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

    /Admin/NewMember.asp, line 23 "

    Thanks Again.
    That could be a number of things. See if this link helps. http://support.microsoft.com/kb/306345

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Posts
    109

    Re: ASP & SQL Writing (Microsoft SQL Server 2008)

    These Lines Are Causing the Problem:
    Cn.Open
    Cn.Execute SQL
    Cn.Close
    Set Cn = Nothing

    Thanks.

  10. #10
    Hyperactive Member
    Join Date
    May 2006
    Posts
    365

    Re: ASP & SQL Writing (Microsoft SQL Server 2008)

    Hello,

    Misinterpretation I beleive has occurred here.

    Code:
    cn.ConnectionString = ConnectionString
    part of the neccessary connection object is the connection string property. Pass it a string and it works.

    Kind regards

    Steve

  11. #11
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: ASP & SQL Writing (Microsoft SQL Server 2008)

    How did I miss that? That would make a big difference.

    Kawser - In case you don't know the syntax, setting the ConnectionString would go between creating the connection object and openning it. I would also consider changing the name of your ConnectionString variable.


    Set Cn = Server.CreateObject("ADODB.Connection")
    cn.ConnectionString = ConnectionString
    Cn.Open

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Posts
    109

    Re: ASP & SQL Writing (Microsoft SQL Server 2008)

    sparbag -> Thank You So Much for pointing this out.

    MarkT -> Now I get this error:

    Microsoft OLE DB Provider for SQL Server error '80004005'

    Cannot open database "Registration" requested by the login. The login failed.

    /Admin/NewMember.asp, line 24

    I am using Windows Authentication Mode with no Password.

    I tried changing the Security Info=False, but still no luck.

    I have the code as follows:

    Code:
    <html>
    
    <head>
    
    <title>New Member - OBMFO</title>
    
    </head>
    
    <body>
    
    DONE !
    
    <%
    FirstName = request("firstname")
    response.write FirstName + " "
    
    LastName = request("lastname")
    response.write LastName 
    
    ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Registration;Data Source=KAWSERHOSSAIN\SQLEXPRESS"
    SQL = "INSERT INTO [Registration Table] (First, Last) VALUES ('" & FirstName & "', '" & LastName & "')" 
    Set Cn = Server.CreateObject("ADODB.Connection")
    cn.ConnectionString = ConnectionString
    Cn.Open 
    Cn.Execute SQL
    Cn.Close
    Set Cn = Nothing
    %>
    
    </body>
    
    </html>
    THANKS A LOT.

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Posts
    109

    Re: ASP & SQL Writing (Microsoft SQL Server 2008)

    I change Integrated Security=True now I am getting this error

    Provider error '80040e21'

    Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.

    /Admin/NewMember.asp, line 24

    Thanks for your help really appreciate it.

  14. #14
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: ASP & SQL Writing (Microsoft SQL Server 2008)

    Try Creating and Configuring a Universal Data Link (.udl) File. Once you have a connection working with that, open the file in notepad and get the correct ConnectionString.

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Posts
    109

    Re: ASP & SQL Writing (Microsoft SQL Server 2008)

    Quote Originally Posted by MarkT View Post
    Try Creating and Configuring a Universal Data Link (.udl) File. Once you have a connection working with that, open the file in notepad and get the correct ConnectionString.
    MarkT,

    That's were I got the ConnectionString from in the first place.

  16. #16
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: ASP & SQL Writing (Microsoft SQL Server 2008)

    The UDL file is going to use the credentials you are currently logged in with when it tests a connection with the use Integrated Security option selected. When your ASP APP is trying to connect it is probably trying to pass the ASP Default User Account. In IIS 6 this would probably be IUSR_<ComputerName>.

    I would try setting up your UDL with a username and password and then test that connection string in you asp code. I would guess the asp account that is trying to open the database doesn't have permissions to do so.

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Posts
    109

    Re: ASP & SQL Writing (Microsoft SQL Server 2008)

    Hello MarkT,

    I tried setting a UserName & Passoword but I get this error:



    BTW: I am using IIS7.

    Thanks.

  18. #18
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: ASP & SQL Writing (Microsoft SQL Server 2008)

    Is there really a user account name test? Have you tried the username and password you log in with?

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Apr 2006
    Posts
    109

    Re: ASP & SQL Writing (Microsoft SQL Server 2008)

    Quote Originally Posted by MarkT View Post
    Is there really a user account name test? Have you tried the username and password you log in with?
    I log in without any password on Windows & on the Server.

    Look here I used all the username and passowd here but still no luck



    Thanks MarkT I really appreciate 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
  •  



Click Here to Expand Forum to Full Width