OleDbConnection(ConfigurationSettings.AppSettings( "dsn")) problem

dominico

Well-known member
Joined
Mar 9, 2005
Messages
57
Programming Experience
3-5
Hello all, could anyone tell me how to make the below statement work please.

Dim objConn AsNew OleDbConnection(ConfigurationSettings.AppSettings("dsn"))

When I run my webform, all I get is a blank page. I run the debug find out that the statement above is the cause of the problem. MSDN doesn't tell me what the statement above mean. I am at my end wits. Please help anyone. Thank you all for reading this post.

I think it has something to do with the "dsn" settings. I don't know how to set it up. Please advise me.


dominico
 
Last edited:

Administrator

VB.NET Forum Admin
Joined
Jun 3, 2004
Messages
1,461
Programming Experience
10+
The Configuration.AppSettings reads name/value pairs in the appSettings section of the web.config, which you may need to add this section. The sample you provided assumes there is a "dsn" value in the web.config such as:

<appSettings>
<add key="dsn" value="my connectionstring here for ODBC DSN connection" />
</appSettings>
 

dominico

Well-known member
Joined
Mar 9, 2005
Messages
57
Programming Experience
3-5
Hi all,

I added the lines above as Neal suggested. It was good. However, I am still having the same problem of getting a blank webpage return. I have no idea why.
 

dominico

Well-known member
Joined
Mar 9, 2005
Messages
57
Programming Experience
3-5
Hi, below is my code. I am trying to display data on a datagrid table:

**********************************************************
Imports System.Data.OleDb

Public Class datagrid

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

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 objConn As New OleDbConnection(ConfigurationSettings.AppSettings("dsn"))

Dim objCmd As OleDbCommand

Protected WithEvents dg As System.Web.UI.WebControls.DataGrid

Dim objRdr As OleDbDataReader

Sub Page_Load(ByVal s As Object, ByVal e As EventArgs)

If Not IsPostBack Then

Call Binddata()

End If

End Sub

Sub Binddata()

objCmd =
New OleDbCommand("SELECT * FROM Customers", objConn)

objConn.Open()

objRdr = objCmd.ExecuteReader()

dg.DataSource = objRdr

dg.DataBind()

objRdr.Close()

objConn.Close()

End Sub

End
Class

********************************************************

Below is the code of part of my web.config after I added the lines suggested:

<configuration>

<appSettings>

<add key="dsn" value="Provider=Microsoft.Jet.OleDb.4.0;Data Source=C:\Database\Customers.mdb" />

</appSettings>



<system.web>


 
Top Bottom