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
<%
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 :wave:
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
<%
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>
Re: ASP & SQL Writing (Microsoft SQL Server 2008)
Quote:
Originally Posted by
MarkT
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."
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.
Re: ASP & SQL Writing (Microsoft SQL Server 2008)
Quote:
Originally Posted by
MarkT
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 :confused:
Thanks.
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.
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.
Re: ASP & SQL Writing (Microsoft SQL Server 2008)
Quote:
Originally Posted by
Kawser
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
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.
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
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
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.
Re: ASP & SQL Writing (Microsoft SQL Server 2008)
I change Integrated Security=True now I am getting this error :ehh:
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.
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.
Re: ASP & SQL Writing (Microsoft SQL Server 2008)
Quote:
Originally Posted by
MarkT
MarkT,
That's were I got the ConnectionString from in the first place.
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.
Re: ASP & SQL Writing (Microsoft SQL Server 2008)
Hello MarkT,
I tried setting a UserName & Passoword but I get this error:
http://img691.imageshack.us/img691/1636/erronc.jpg
BTW: I am using IIS7.
Thanks.
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?
Re: ASP & SQL Writing (Microsoft SQL Server 2008)
Quote:
Originally Posted by
MarkT
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 :sick:
http://img827.imageshack.us/img827/6553/usern.jpg
Thanks MarkT I really appreciate it.