ado.net help with access

Discussion in 'Databases' started by TheInnovator, Mar 27, 2008.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Thanks. As a newbie to ASP.NET and ADO.Net, I read in a few articles that it's more secure to put the connectionstring in web.config; that's why I tried that method.
    But I will go ahead and put it in the code page.

    Thanks again.

    -Isaac-
     
  2. I'm trying to insert data from my contact page into my ACCESS database, but I get squigly lines underneath, 'connectionString', 'insertSql' and 'cmd'. When I scroll over 'connectionsSring' and 'cmd', it says 'it's not declared'. When I scroll over 'insertSql' it reads, 'array bounds cannot appear in type specifiers'.

    I'm also having issues with my webconfig file. See below:


    Protected Sub Submit1_ServerClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit1.ServerClick

    'Define ADO.NET objects.
    Dim insertSQL As String
    insertSQL = 'INSERT INTO tblContact ( '
    insertSQL &= 'fname,lname,email,message) '
    insertSQL &= 'VALUES ('
    insertSQL &= '@fname,@lname,@email,@message)'


    Dim accConn As New Data.OleDb.OleDbConnection(connectionString)
    Dim cmd As OleDbCommand(insertSQL, accConn)

    'Add Parameters
    cmd.Parameters.AddWithValue('@fname', fname.Text)
    cmd.Parameters.AddWithValue('@lname', lname.Text)
    cmd.Parameters.AddWithValue('@email', email.Text)
    cmd.Parameters.AddWithValue('@message', comment.Text)


    ' accConn.ConnectionString = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' & Server.MapPath('/area.mdb')

    Dim added As Integer = 0
    Try
    accConn.Open()
    added = cmd.ExecuteNonQuery()

    Catch accError As Exception
    lblInfo.Text = 'There is an issue with the database at this time, please send an email to <a href='mailto:[email protected]'>[email protected]</a>'
    Finally
    accConn.Close()
    End Try
    End Sub


    'snippet of Web.config file
    <connectionStrings>
    <add name='webarea' connectionString='Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' & Server.MapPath('/iwebarea.mdb')/>
    </connectionStrings>
    <connectionStrings/>

    Thanks for any help you can provide.
     
  3. Yes,for protectionwithyour Access DB youcan use a few tricks.
    Discountasp.net provides us with a protected folder for Access DBs, to make it more secure.
    _database

    It's not imperative that you use that folder but it's there if you want more protection.

    There are even better methods if you bind data controls to your access DB.
    http://asp.net/learn/data-access/
    Salute,
    Mark
     
  4. Bruce

    Bruce DiscountASP.NET Staff

    The only benefit for putting connection string in web.config is when your connection string contains login information (for SQL not access). To take advantage of this enhanced security, the web.config should be encrypted as well.


    For Access, its probably easier to just include the connection string in the code.


    Bruce

    DiscountASP.NET
    www.DiscountASP.NET
     
  5. I think you'd do a lot better to get away from storing the conn for that Access DB in the web.config...
    Just create it on the code page.

    Dim accConn As String = "provider=Microsoft.Jet.OLEDB.4.0;data source=" + Server.MapPath("/area.mdb")

    To do it the way you're trying you'll need to bind the database to the controls.

    Are you testing your page in Visual Studio?
    btw, here's anADO tutorial:
    http://www.w3schools.com/aspnet/aspnet_dbconnection.asp
    Salute,
    Mark
     
  6. OK. Thanks Mark and Bruce. I appreciate your help.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page