Solved

No value given for one or more required parameters. Login issue

Posted on 2006-07-13
6
226 Views
Last Modified: 2008-02-26
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.OleDbException: No value given for one or more required parameters. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.OleDb.OleDbCommand.ExecuteReader() at Bioness.login.AttemptLogin(String sUserName, String sPassword) in c:\inetpub\wwwroot\Bioness\admin\login.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.DebuggerStepThrough()> 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.HtmlInputImage
    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.RequiredFieldValidator
    Protected WithEvents rfvPassword As System.Web.UI.WebControls.RequiredFieldValidator

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration 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.ImageClickEventArgs) 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.Text, "'", "''") & "'"
            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.aspx")
            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:
http://www.experts-exchange.com/Databases/Q_21916801.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("@user", sUserName);
            gdcCMD.Parameters.Add("@password", sPassword);
            gdrDR = gdcCMD.ExecuteReader
            If gdrDR.Read() Then
                glID = gdrDR.Item(0)
                Session("login") = True
                AttemptLogin = True
                Response.Redirect("admin.aspx")
            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
0
Comment
Question by:Dalkalion
  • 3
  • 3
6 Comments
 
LVL 11

Accepted Solution

by:
walkerke earned 500 total points
ID: 17109368
This error is commonly caused by typos in the field names in your query statement. Make sure that the fields you reference in your query are not misspelled and exist in your database on the remote server.
0
 

Author Comment

by:Dalkalion
ID: 17110656
You're right. I had a typo.
0
 
LVL 11

Expert Comment

by:walkerke
ID: 17110893
Why only a "B" grade?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:Dalkalion
ID: 17111089
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?
0
 
LVL 11

Expert Comment

by:walkerke
ID: 17111214
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.
0
 

Author Comment

by:Dalkalion
ID: 17111950
Your right, I'm sorry...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
The viewer will learn how to count occurrences of each item in an array.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now