Dalkalion
asked on
No value given for one or more required parameters. Login issue
Hello all,
I've got a login page that works on my machine but not my remote server.
I get this error:
System.Data.OleDb.OleDbExc eption: No value given for one or more required parameters. at System.Data.OleDb.OleDbCom mand.Execu teCommandT extErrorHa ndling(Int 32 hr) at System.Data.OleDb.OleDbCom mand.Execu teCommandT extForSing leResult(t agDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCom mand.Execu teCommandT ext(Object & executeResult) at System.Data.OleDb.OleDbCom mand.Execu teCommand( CommandBeh avior behavior, Object& executeResult) at System.Data.OleDb.OleDbCom mand.Execu teReaderIn ternal(Com mandBehavi or behavior, String method) at System.Data.OleDb.OleDbCom mand.Execu teReader(C ommandBeha vior behavior) at System.Data.OleDb.OleDbCom mand.Execu teReader() at Bioness.login.AttemptLogin (String sUserName, String sPassword) in c:\inetpub\wwwroot\Bioness \admin\log in.aspx.vb :line 58
Here is my line 58:
gdrDR = gdcCMD.ExecuteReader
The rest of my code:
Imports System.Data.OleDb
Public Class login
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
End Sub
Protected WithEvents lblCheck As System.Web.UI.WebControls. Label
Protected WithEvents Form1 As System.Web.UI.HtmlControls .HtmlForm
Protected WithEvents btnLogin As System.Web.UI.HtmlControls .HtmlInput Image
Protected WithEvents txtUser As System.Web.UI.WebControls. TextBox
Protected WithEvents txtPassword As System.Web.UI.WebControls. TextBox
Protected WithEvents rfvUser As System.Web.UI.WebControls. RequiredFi eldValidat or
Protected WithEvents rfvPassword As System.Web.UI.WebControls. RequiredFi eldValidat or
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclara tion As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Dim gdcDataConnection As New OleDbConnection("Provider= Microsoft. Jet.OLEDB. 4.0;Data Source=C:\db\users.mdb;")
Dim gdcCMD As New OleDbCommand
Dim gdrDR As OleDbDataReader
Dim gsCnn As String
Dim glID As Long
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub btnLogin_ServerClick(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEv entArgs) Handles btnLogin.ServerClick
Dim sPassword As String
Dim sUserName As String
AttemptLogin(sUserName, sPassword)
End Sub
Private Function AttemptLogin(ByVal sUserName As String, ByVal sPassword As String) As Boolean
Dim sSQL As String
Dim s As String = "" 'initialize to default value
Try
sSQL = "SELECT ID FROM my_users WHERE username = '" & Replace(Me.txtUser.Text, "'", "''") & "' and password = '" & Replace(Me.txtPassword.Tex t, "'", "''") & "'"
gdcCMD = New OleDbCommand(sSQL, gdcDataConnection)
gdcDataConnection.Open()
gdrDR = gdcCMD.ExecuteReader()
If gdrDR.Read() Then
glID = gdrDR.Item(0)
Session("login") = True
AttemptLogin = True
Response.Redirect("admin.a spx")
Else
Session("login") = False
AttemptLogin = False
s = "Log in Failed. Try again."
End If
gdrDR.Close()
gdcDataConnection.Close()
Catch ex As Exception
s = ex.ToString
Finally
lblCheck.Text = s
End Try
End Function
End Class
And a previous exchange:
https://www.experts-exchange.com/questions/21916801/I-can't-seem-to-connect-to-my-database.html
I tried using this but it didn't work at all:
So here's what I'm thinking you could try...
Private Function AttemptLogin(ByVal sUserName As String, ByVal sPassword As String) As Boolean
Dim sSQL As String
Dim s As String = ""
Try
gdcDataConnection.Open()
sSQL = "SELECT [ID] FROM [my_users] WHERE [user] = @user and [password] = @password"
gdcCMD = New OleDbCommand(sSQL, gdcDataConnection)
gdcCMD.Parameters.Add("@us er", sUserName);
gdcCMD.Parameters.Add("@pa ssword", sPassword);
gdrDR = gdcCMD.ExecuteReader
If gdrDR.Read() Then
glID = gdrDR.Item(0)
Session("login") = True
AttemptLogin = True
Response.Redirect("admin.a spx")
Else
Session("login") = False
AttemptLogin = False
s = "Log in Failed. Try again."
End If
Catch ex As Exception
Session("login") = False
s = ex.ToString
Finally
lblCheck.Text = s
If Not gdrDR Is Nothing Then
gdrDR.Close()
End If
If Not gdcDataConnection Is Nothing Then
gdcDataConnection.Close()
End If
End Try
End Function
I've got a login page that works on my machine but not my remote server.
I get this error:
System.Data.OleDb.OleDbExc
Here is my line 58:
gdrDR = gdcCMD.ExecuteReader
The rest of my code:
Imports System.Data.OleDb
Public Class login
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.Debugg
End Sub
Protected WithEvents lblCheck As System.Web.UI.WebControls.
Protected WithEvents Form1 As System.Web.UI.HtmlControls
Protected WithEvents btnLogin As System.Web.UI.HtmlControls
Protected WithEvents txtUser As System.Web.UI.WebControls.
Protected WithEvents txtPassword As System.Web.UI.WebControls.
Protected WithEvents rfvUser As System.Web.UI.WebControls.
Protected WithEvents rfvPassword As System.Web.UI.WebControls.
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclara
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Dim gdcDataConnection As New OleDbConnection("Provider=
Dim gdcCMD As New OleDbCommand
Dim gdrDR As OleDbDataReader
Dim gsCnn As String
Dim glID As Long
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub btnLogin_ServerClick(ByVal
Dim sPassword As String
Dim sUserName As String
AttemptLogin(sUserName, sPassword)
End Sub
Private Function AttemptLogin(ByVal sUserName As String, ByVal sPassword As String) As Boolean
Dim sSQL As String
Dim s As String = "" 'initialize to default value
Try
sSQL = "SELECT ID FROM my_users WHERE username = '" & Replace(Me.txtUser.Text, "'", "''") & "' and password = '" & Replace(Me.txtPassword.Tex
gdcCMD = New OleDbCommand(sSQL, gdcDataConnection)
gdcDataConnection.Open()
gdrDR = gdcCMD.ExecuteReader()
If gdrDR.Read() Then
glID = gdrDR.Item(0)
Session("login") = True
AttemptLogin = True
Response.Redirect("admin.a
Else
Session("login") = False
AttemptLogin = False
s = "Log in Failed. Try again."
End If
gdrDR.Close()
gdcDataConnection.Close()
Catch ex As Exception
s = ex.ToString
Finally
lblCheck.Text = s
End Try
End Function
End Class
And a previous exchange:
https://www.experts-exchange.com/questions/21916801/I-can't-seem-to-connect-to-my-database.html
I tried using this but it didn't work at all:
So here's what I'm thinking you could try...
Private Function AttemptLogin(ByVal sUserName As String, ByVal sPassword As String) As Boolean
Dim sSQL As String
Dim s As String = ""
Try
gdcDataConnection.Open()
sSQL = "SELECT [ID] FROM [my_users] WHERE [user] = @user and [password] = @password"
gdcCMD = New OleDbCommand(sSQL, gdcDataConnection)
gdcCMD.Parameters.Add("@us
gdcCMD.Parameters.Add("@pa
gdrDR = gdcCMD.ExecuteReader
If gdrDR.Read() Then
glID = gdrDR.Item(0)
Session("login") = True
AttemptLogin = True
Response.Redirect("admin.a
Else
Session("login") = False
AttemptLogin = False
s = "Log in Failed. Try again."
End If
Catch ex As Exception
Session("login") = False
s = ex.ToString
Finally
lblCheck.Text = s
If Not gdrDR Is Nothing Then
gdrDR.Close()
End If
If Not gdcDataConnection Is Nothing Then
gdcDataConnection.Close()
End If
End Try
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Why only a "B" grade?
ASKER
I'm sorry. I'm still really new at this and I don't understand the grading system all that well. Can you blame a girl? I mean, is there a way I can change it to an A?
I don't think you can change it, nor do I expect it. I just thought since I nailed that one on the first comment it would deserve an A.
ASKER
Your right, I'm sorry...
ASKER