Hakan Subaşı
Hakan Subaşı

Reputation: 61

SQL Server 2005 Connection with ASP classic

I want to connect main page with user login in ASP. I use MS SQL 2005 and I wrote below codes but I didnt get any result. Could anyone help me about connectionstrings?

Dim MyLogin  
Set MyLogin = Server.CreateObject("ADODB.Connection")   
MyLogin.Open "Provider=MSDASQL;Data Source=10.10.10.10; Initial Catalog=testdb;       User      Id=123; Password=456;"

SQLtemp = "SELECT * FROM users WHERE UserName = '" & Request.Form("username") & "'   AND    Password = '" & Request.Form("password") & "'"

Set rs = MyLogin.Execute(SQLtemp)

while not rs.eof

If Request.Form("username") = rs("UserName") AND Request.Form("password") = rs("Password") Then

dim Your_UserName
Your_UserName = rs("UserName")
dim Date_In
Date_In = rs("Entry_Date")

Response.Cookies("UserName") = Your_UserName
Response.Cookies("still") = Date_In

Session.TimeOut = 20
Session("UserName") = "Yes"

Response.Redirect "protected.asp?UserLoggedIn=" & Your_UserName
Else
Session("Message") = ("<font face=""Verdana"" size=""2"" color=""#FF0000"">Login     Failed! </font><font face=""Verdana"" size=""2""   color=""#0000FF"">Incorrect Username & Password.</font>")
Response.Redirect ("login.asp")
Response.End
End If

rs.MoveNext
Wend

OnError Response.Redirect ("login.asp")


rs.Close
MyLogin.Close
set MyLogin = Nothing

%>

Upvotes: 0

Views: 994

Answers (1)

John
John

Reputation: 4663

Try these.

Provider=SQLOLEDB;Data Source=127.0.0.1;Initial Catalog=dbname;User Id=youruid;Password=yourpwd

Provider=SQLNCLI;Server=127.0.0.1;Database=dbname;Uid=youruid;Pwd=yourpwd

Is your database the express version. if it is you need to add \SQLEXPRESS after the data source IP

Upvotes: 1

Related Questions