p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 18th, 2008, 11:09 PM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2008
Location: Pawleys Island, SC, USA.
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old November 19th, 2008, 12:58 AM
Friend of Wrox
Points: 4,805, Level: 29
Points: 4,805, Level: 29 Points: 4,805, Level: 29 Points: 4,805, Level: 29
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,323
Thanks: 3
Thanked 70 Times in 69 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old November 19th, 2008, 10:49 PM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2008
Location: Pawleys Island, SC, USA.
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:



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old November 19th, 2008, 11:25 PM
Friend of Wrox
Points: 4,805, Level: 29
Points: 4,805, Level: 29 Points: 4,805, Level: 29 Points: 4,805, Level: 29
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,323
Thanks: 3
Thanked 70 Times in 69 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>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old November 23rd, 2008, 10:46 PM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2008
Location: Pawleys Island, SC, USA.
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)


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old November 24th, 2008, 11:41 AM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2008
Location: Pawleys Island, SC, USA.
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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

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



All times are GMT -4. The time now is 12:55 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc