DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Thu, 9 Aug 2007 15:36:02 -0700,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    pelegk1


ConfigurationManager.connectionStrings = Object reference not set   
i work on winxp with Net2 ver 2.0.50727 in the IIS (under ASP.NET)
in my web.config file i have :
[vb]
<configuration>
  <connectionStrings>
    <add name="local_con" connectionString="Data 
Source=.\SQLEXPRESS;Integrated Security=False;User 
Id=xxx;Password=xxxx;database=db1"
   providerName="System.Data.SqlClient" />
    
  </connectionStrings>
.....
</configuration>
[/vb]
when i use on my pc this code :
[code]
<%@ Page Language="vb" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<%@ import Namespace="System.Configuration" %>


<script runat="server">

    Sub Page_Load(sender As Object, e As EventArgs)
    'declarations
    Dim conLath As SqlConnection
    Dim cmdLath As SqlCommand
    Dim rdrLath As SqlDataReader
    Dim connString As String = 
ConfigurationManager.connectionStrings("local_con").ConnectionString
    
	response.write("1")
    Using myConnection As New SqlConnection(connString)
                Try
                    myConnection.Open()
                Catch Obj As Exception
                    Response.Write(Obj.Message)
                    Response.End()
                End Try
                'Create a SqlCommand instance
                Dim myCommand As New SqlCommand("select * from tbl1", 
myConnection)
                Dim reader As SqlDataReader = myCommand.ExecuteReader()
                myConnection.Close()
            End Using
    End Sub

</script>
            
[/code]
everything works great!
when  i move my project to win2003 server i recive the next error : (the 
ASP.NET version there is the same!)
[quote]
Server Error in '/mySite' Application.
--------------------------------------------------------------------------------

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 12:     Dim cmdLath As SqlCommand
Line 13:     Dim rdrLath As SqlDataReader
Line 14:     Dim connString As String = 
ConfigurationManager.connectionStrings("local_Con").ConnectionString

 

Source File: C:\Inetpub\wwwroot\mySite\try2connec2.aspx    Line: 14 

Stack Trace: 


[NullReferenceException: Object reference not set to an instance of an 
object.]
   ASP.try2connec2_aspx.Page_Load(Object sender, EventArgs e) in 
C:\Inetpub\wwwroot\mySite\try2connec2.aspx:14
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, 
Object t, EventArgs e) +15
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, 
EventArgs e) +34
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Page.ProcessRequestMain(Boolean 
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
[/quote]

any idea why this can happend?
thnaks in advance
peleg
Date:Thu, 9 Aug 2007 15:36:02 -0700   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us