RE: Trying to use ExecuteNonQuery on Command crashes

Tech-Archive recommends: Fix windows errors by optimizing your registry



Dessi Bravo (DessiBravo@xxxxxxxxxxxxxxxxxxxxxxxxx) writes:
> I you could help me in this code. I am trying to authenticate the code
> in a login page that i created but continue to get an error in the
> ExecuteReader. It says that it requires a connection and available
> connection. the current state is closed.
> Here is the code that i created:
> I appreciate your assistance.
> Dim mypath = Application.StartupPath & "\password.mdb"
> Dim Password = ""
> Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=" & mypath & ";Jet OLEDB:Database Password=" & Password)
> Dim cmd As OleDbCommand
>
> Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles btnLogin.Click
> Dim sql = "SELECT Username,Password FROM Password WHERE Username =
> '" & txtUsername.Text & "' AND Password = '" & txtPassword.Text & "'"
>
> cmd = New OleDbCommand(sql, conn)
> Dim dr As OleDbDataReader = cmd.ExecuteReader
> If conn.State <> ConnectionState.Open Then
> conn.Open()
> End If

You should connect before you call ExecuteReader.

As for the lack or response, this group is not really about ADO .Net,
but using the OLE DB API. Next time you should probably try
microsoft.public.dotnet.framework.adonet.
--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
.



Relevant Pages

  • Login Seems OK but doesnt behave correctly
    ... Using MS SQL server on a shared host (www.joglab.com shows the ... login but not behaving on the pages ie LoginView/ Login Status not ... Web Site Administration Tool I get "Could not establish a connection ... <LoggedInTemplate> ...
    (comp.databases.ms-sqlserver)
  • Re: forms authentction against sql server 2000
    ... Try using Query Analyzer using the same login and see. ... I'm using sql server 2000 on a remote machine and I have a login.aspx page ... "An error has occurred while establishing a connection to the server. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Login failure...
    ... loop) -- I'm suspecting the connection overhead with rapid ... connection/disconnect timing problem (i.e. my remote SQL Server can't keep ... > Private Sub MyMethod ... and I get Login failure. ...
    (microsoft.public.dotnet.framework.adonet)
  • Whats the best way to open a Connection to DB in the WEB envoironment
    ... applied an ideal logic to open a connection from my application. ... Backend Database: SQL Server 2000. ... I have created "Login" for each users in SQL Server 2000 and all of them ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Remote connection failed
    ... create new username/password login with SQL Server ... Select Authentication = SQL Server and Windows on Security tab of SQL ... Connection string in SQLDriverConnect string is "Driver=; ...
    (microsoft.public.sqlserver.connect)