ConfigurationManager.connectionStrings = Object reference not set

G

Guest

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>
everything works great!
when i move my project to win2003 server i recive the next error : (the
ASP.NET version there is the same!)
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

any idea why this can happend?
thnaks in advance
peleg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top