Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 23rd, 2004, 02:40 PM
Friend of Wrox
 
Join Date: Apr 2004
Location: Preston, Lancashire, United Kingdom.
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default Database Connection with Web.Config

Hi there,

I literally just started to develope my own application after working through the beginners guide to ASP.NET in VB.NET to test what I had learnt. I have come across a problem.

When i am pulling user name and password from the database with the database string in the page code it is fine. but when i replace it with the ConfigurationSettings.AppSettings("connectionStrin g") it throws me errors. i have matched the syntax... this is my web.config

<?xml version="1.0" encoding="UTF-8" ?>

<configuration>

            <appSettings>
            <add key="connectionString" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\DJSTORE\database\store.m db"/>
         </appSettings>

    <system.web>

        <authentication="Forms">

            <forms name=".djstore" loginurl="admin/login.aspx" protection="Validation" timeout="999999" />

        </authentication>

        <authorization>
            <allow users="*" />
            <deny users="*" />
        </authorization>

    </system.web>

</configuration>

And this is my page so far:

<%@ Page Language="VB" %>
<script runat="server">

    ' This is the code for the Login Button

    Sub LoginBtn_Click(Sender as Object, E as EventArgs)

        Dim UsersDB as System.Data.iDataReader
        UsersDB = Users()
        While UsersDB.Read

            Dim UserLogin as String = UsersDB("UserName")
            Dim UserPassword as String = UsersDB("UserPass")
            Dim AdminLevel as String = UsersDB("UserLevel")

              If (UserName.Text = UserLogin And UserPass.Text = UserPassword) Then

                Dim UserNameCookie as New HttpCookie("UserNameCookie")
                UserNameCookie.Value = UserName.Text
                Response.Cookies.Add(UserNameCookie)

                Dim UserLevelCookie as New HttpCookie("UserLevelCookie")
                UserLevelCookie.Value = AdminLevel
                Response.Cookies.Add(UserLevelCookie)

                FormsAuthentication.RedirectFromLoginPage(UserName .Text, true)

              Else

                Msg.Text = "Invalid User Name or Password: Please try again!"

              End If

            End While

    End Sub


    ' This creates the database connection and reads the information for admin logins

    Function Users() As System.Data.IDataReader
        Dim connectionString As String = ConfigurationSettings.AppSettings("connectionStrin g")
        Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString )
        Dim queryString As String = "SELECT [UserDetails].[UserName],[UserDetails].[UserPass], [UserDetails].[UserLevel] FROM [UserDetails]"

        Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
        dbCommand.CommandText = queryString
        dbCommand.Connection = dbConnection

        dbConnection.Open
        Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavio r.CloseConnection)

        Return dataReader
    End Function

</script>
<html>
<head>
    <link id="css" href="../includes/shop.css" type="text/css" rel="stylesheet" />
</head>
<body>


    <form runat="server">
        <p align="center">



            <img src="images/logo.gif" />
        </p>
        <p align="center">
            User Name:&nbsp;<asp:TextBox id="UserName" runat="server"></asp:TextBox>
            <br />
            Password:
            <asp:TextBox id="UserPass" runat="server" textmode="Password"></asp:TextBox>
        </p>
        <p align="center">
            <asp:Button id="LoginBtn" onclick="LoginBtn_Click" runat="server" Text="Login"></asp:Button>
            <br />
            <asp:Label id="Msg" runat="server" forecolor="red"></asp:Label>
        </p>
    </form>
</body>
</html>

cheers for any help, if it cant be done then i will just have to do it with the direct connection which is not really what i wanted.

__________________
David Jenkins
  #2 (permalink)  
Old July 23rd, 2004, 03:30 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

You can do it with appsettings, try:

ConfigurationSettings.AppSettings.Get("connectionS tring")

If that doesn't work, try:

Dim objKey As Specialized.NameValueCollection = ConfigurationSettings.AppSettings
Dim connectionString As String = objKey.Get("connectionString")

Brian
  #3 (permalink)  
Old July 24th, 2004, 10:18 AM
Friend of Wrox
 
Join Date: Apr 2004
Location: Preston, Lancashire, United Kingdom.
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default

Ok none of those worked. but it doesnt matter i decided just to hard code the database connection into it..... i suck at this databse reading and inserting.

I am now trying to insert something into the database. i used my own code to start with but that i really not working... so used the example on page 311 of the beginners guides. in debug mode it gives me...

Exception Details: System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.

Line 22: dbCommand.Parameters.Add(NameParam)
Line 23:
Line 24: dbCommand.ExecuteNonQuery() this is where the error is
Line 25:
Line 26: dbConnection.Close()

can anyone help me with this one

  #4 (permalink)  
Old July 26th, 2004, 07:50 AM
Friend of Wrox
 
Join Date: Apr 2004
Location: Preston, Lancashire, United Kingdom.
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default

So anyone got any ideas on the above? Any help is appreciated.

  #5 (permalink)  
Old July 26th, 2004, 02:49 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi there,

This is CLASSIC ASP forum, may be you would get quicker response, had it been posted in a dotnet ("ASPX Beginners") forum here.

Cheers!

_________________________
- Vijay G
Strive for Perfection
  #6 (permalink)  
Old July 26th, 2004, 05:41 PM
Friend of Wrox
 
Join Date: Apr 2004
Location: Preston, Lancashire, United Kingdom.
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default

Sorry! Thought asp databases would cover both.

  #7 (permalink)  
Old July 26th, 2004, 06:04 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

No Problem, your post would be viewed many times there than what it would be here. So chances of response are more there than here.;)

_________________________
- Vijay G
Strive for Perfection
  #8 (permalink)  
Old July 26th, 2004, 06:10 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

That's a database error, which probably means that there are one more insert fields than there are values passed in, or the opposite of the previous, or that there are ' around a field that shouldn't have them, or again the opposite.

I didn't see your insert, so I can't tell.

In addition, using the config file with ConfigurationSettings.AppSettings should have worked. Maybe there's an issue with something else. Turning Option Explicit on may reveal something.

Brian


Similar Threads
Thread Thread Starter Forum Replies Last Post
connection string issues, web.config file issues kaliaparijat ASP.NET 2.0 Professional 1 June 12th, 2008 08:07 AM
Blog - Web.Config Settings for Access Database kanzeon4 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 3 April 5th, 2008 07:46 AM
setting connection string in the web.config ACE2084 ADO.NET 2 January 6th, 2005 04:33 PM
Putting connection in web.config issue mar0364 ASP.NET 1.0 and 1.1 Basics 7 October 20th, 2004 06:59 AM
Variable Path in web.Config Connection String? ElPato General .NET 4 June 21st, 2004 05:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.