Wrox Programmer Forums
|
BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9
This is the forum to discuss the Wrox book Professional ASP.NET 2.0 Special Edition by Bill Evjen, Scott Hanselman, Devin Rader, Farhan Muhammad, Srinivasa Sivakumar; ISBN: 9780470041789
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 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
 
Old November 18th, 2008, 11:09 PM
Registered User
 
Join Date: Nov 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Something Fundamental

I am having a very frustrating time trying to use Professional ASP.NET 2.0 Every time I try to run code I get a fundamental error message. I open the downloaded code as a text file; save it as an ASPX file into an ASP.Net website that I created with Visual Web Developer 2005 and then open the code file. I then click on debug and select run without debugging and get very basic error messages. Can anyone tell me what I am doing wrong?
For example, doing this with the code for listing 12-1, I get the following error message (Note Line 16 is all on one line in the file):

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 14:
Line 15: MyConnection = New SqlConnection()
Line 16: MyConnection.ConnectionString = ConfigurationManager.ConnectionStrings("DSN_Northw ind").ConnectionString
Line 17:
Line 18:


Source File: D:\websites\pbocchurch\WebSite1\12-01.aspx Line: 16

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
   ASP._12_01_aspx.Page_Load(Object sender, EventArgs e) in D:\websites\pbocchurch\WebSite1\12-01.aspx:16
   System.Web.Util.CalliHelper.EventArgFunctionCaller (IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Cal lback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053
 
Old November 19th, 2008, 12:58 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Well, if I were GUESSING, I'd say that there is *NO* ConnectionStringSettings with the name "DSN_Northwind" in that collection.

Have you debugged? Have you looked inside ConfigurationManager to see what ConnectionStrings it is holding??

If worst comes to worst, you could check to see just what is in there with code something like the snippet shown here:
http://msdn.microsoft.com/en-us/libr...onmanager.aspx
 
Old November 19th, 2008, 10:49 PM
Registered User
 
Join Date: Nov 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the response. I have this connection string in my web.config file

<connectionStrings>
        <add name="committeesConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=D:\websites\pbocchurch\WebSite1\committees. mdb"
            providerName="System.Data.OleDb" />
</connectionStrings>

And am getting the following error:
Keyword not supported: 'provider'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Keyword not supported: 'provider'.

Source Error:


Line 14:
Line 15: MyConnection = New SqlConnection()
Line 16: MyConnection.ConnectionString = ConfigurationManager.ConnectionStrings("committees ConnectionString").ConnectionString
Line 17:
Line 18:



 
Old November 19th, 2008, 11:25 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

You are ALREADY specifying the provider via the PROVIDERNAME= attribute. So I'd bet that the PROVIDER= is unnecessary and, of course, not allowed.

Have never used this, but give it a try:

Code:
<connectionStrings>
   <add name="committeesConnectionString" 
        connectionString="Data Source=D:\websites\pbocchurch\WebSite1\committees.mdb"
        providerName="System.Data.OleDb" 
   />
</connectionStrings>
 
Old November 23rd, 2008, 10:46 PM
Registered User
 
Join Date: Nov 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well now I have a connection string and connection, I think. I am trying to verify by writing the content of the "major" column in the "major" table in the committees.mdb database. (Yes the field and table have the same name.) When I run this code I get a blank browser window. Can you please take a look? Where I want to get to is be able to update the fields in one table's particular record with specific fields from a record selected from a second table. But first I have to connect! Here is my code:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="connect.aspx.vb" Inherits="connect" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script language="VB" runat="server">
  sub Page_Load(sender as Object, e as EventArgs)
    'Create a connection string
    Dim connString as String
        connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & _
                       "committees.mdb;"

    'Open a connection
    Dim objConnection as OleDbConnection
    objConnection = New OleDbConnection(connString)
    objConnection.Open()

    'Specify the SQL string
        Dim strSQL As String = "SELECT * FROM major"

    'Create a command object
    Dim objCommand as OleDbCommand
    objCommand = New OleDbCommand(strSQL, objConnection)

    'Get a datareader
    Dim objDataReader as OleDbDataReader
    objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConn ection)
        Dim asd As String
        While objDataReader.Read()
            asd = objDataReader("major")
            Response.Write(asd)
        End While

        'Close the datareader/db connection
        objDataReader.Close()
    End Sub
</script>

I have also tried this with the following line
asd = objDataReader(1)


 
Old November 24th, 2008, 11:41 AM
Registered User
 
Join Date: Nov 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, I connected! FInally. I had to change the connection string from

connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & _
                       "committees.mdb;"

to

Dim cn As New Data.OleDb.OleDbConnection("PROVIDER=Microsoft.Jet .OLEDB.4.0;DATA SOURCE=" & _
                       "D:\websites\pbocchurch\church\aspx\committees.mdb ;")

I am using IIS on my Windows XP Pro PC to test my pages. When I used ASP, just committees.mdb worked, since the database is in the same folder as the asp file (or in this case aspx). NOw I get "Could not find file 'C:\WINDOWS\system32\committees.mdb'" Do I have to do something in IIS? The folder is set to run asp.net






Similar Threads
Thread Thread Starter Forum Replies Last Post
Fundamental namespace problem? danielh XSLT 4 January 6th, 2008 06:24 AM





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