Click here to Skip to main content
14,920,009 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I am trying to read logon information and validate them against stored user name and passwords within a Jet database.

Later I want to use an SQL Server database, however, I have an installation problem, so I am using Access temporarily.

C#
[__i__]Logon.aspx.cs
 protected void Page_Load(object sender, EventArgs e)
    {
        System.Data.OleDb.OleDbConnection ConnectionToOleDb = new System.Data.OleDb.OleDbConnection("Provider= Microsoft.Jet.OLEDB.4.0;|DataDirectory|LibrarySystem.accdb");
            
        try {
            //1. connect to database
            ConnectionToOleDb.Open();
            //2. read logon credentials and match them to input
            ???
        }
        catch (Exception ex) { throw ex; } //strongly typed errors need to be included..
        finally
        {
            ConnectionToOleDb.Close();
        }

...
Logon.aspx
 function Submit1_onclick() {
            /* Logon credentials to be submitted and verified by the server control */
            var user = document.getElementById('user').Value;
            var pwd = document.getElementById('pwd1').Value;
            if (user == "user") && (pwd == "password") 
                    {
                        return true;
                        document.forms[0].submit();
                    }          


web.config
...
HTML
<configuration>
  <connectionstrings>
      <add name="CustomerDataConnectionString">
        connectionString="Provider=Microsoft.Jet.OLEDB.4.0;
        Data Source=|DataDirectory|LibrarySystem.accdb"
     providerName="System.Data.OleDb" />
  </add></connectionstrings>
...</configuration>
Posted
Updated 23-Dec-13 13:49pm
v2
Comments
OriginalGriff 23-Dec-13 15:12pm
   
And?
Your problem is?

1 solution

Don't do anything in Page Load. You should create Connection and match credentials inside Button Click Event.

Refer- Login form with access database[^] for one example.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900