Showing posts with label deploying. Show all posts
Showing posts with label deploying. Show all posts

Tuesday, March 6, 2012

"Object reference not set to an instance of an object. " and connection string

Hi, I am deploying my web through a web hosting services which provides SQL database support. I got following errors whenever I try to open my webpage,which never happen when I run my web on the local machine.

I have my connection string configured in my web.config as below:

<addname="ArtHouseConnection"connectionString="Server=serveripaddress; Integrated Security=True; Database=arteh3_database;User Id=username;Password=password;"providerName="System.Data.SqlClient"/>

<addname="ASPNETDBConnectionString1"connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True"providerName="System.Data.SqlClient"/>

This is the source code where error was generated:

public

staticclass ArtHouseConfiguration

{

//cache connection stringprivatereadonlystaticstring dbConnectionString;//cache data provider nameprivatereadonlystaticstring dbProviderName;

privatereadonlystaticstring siteName;

//initialize constructor propertiesstatic ArtHouseConfiguration()

{

dbConnectionString = ConfigurationManager.ConnectionStrings[

"ArtHouseConnection"].ConnectionString;

dbProviderName = ConfigurationManager.ConnectionStrings[

"ArtHouseConnection"].ProviderName;

siteName = ConfigurationManager.AppSettings["SiteName"];

}


and finally this is the error mg I got:

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 30: static ArtHouseConfiguration()Line 31: {Line 32: dbConnectionString = ConfigurationManager.ConnectionStrings["ArtHouseConnection"].ConnectionString;Line 33: dbProviderName = ConfigurationManager.ConnectionStrings["ArtHouseConnection"].ProviderName;Line 34:


Source File:d:\inetpub\vhosts\artehouse.org\httpdocs\App_Code\ArtHouseConfiguration.cs Line:32

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.] ArtHouseConfiguration..cctor() in d:\inetpub\vhosts\artehouse.org\httpdocs\App_Code\ArtHouseConfiguration.cs:32[TypeInitializationException: The type initializer for 'ArtHouseConfiguration' threw an exception.] ArtHouseConfiguration.get_EnableErrorLogEmail() in d:\inetpub\vhosts\artehouse.org\httpdocs\App_Code\ArtHouseConfiguration.cs:74 Utilities.LogError(Exception ex) in d:\inetpub\vhosts\artehouse.org\httpdocs\App_Code\Utilities.cs:100 ASP.global_asax.Application_Error(Object sender, EventArgs e) in d:\inetpub\vhosts\artehouse.org\httpdocs\Global.asax:20 System.EventHandler.Invoke(Object sender, EventArgs e) +0 System.Web.HttpApplication.RaiseOnError() +182

Anyone got any ideas? thank you!


Hi genjioo,

This seems to have something to do with the web.config file.

Please check if the connections strings have been put under the configuration\connectionStrings section. Here is a typical sample

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="ConnStr1" connectionString="LocalSqlServer: data source=127.0.0.1;Integrated Security=SSPI;Initial Catalog=aspnetdb"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>

If it is not put under this, the ConfigurationManager.ConnectionStrings will not be able to find it.

Friday, January 27, 2012

HELP ! Disappearing objects

We are supposed to be deploying to SQL2K5 this friday night. I've been
taking backups from our SQL 2K server and restoring them directly on our 2K5
box. Everything seems to work ok except for one of our databases. When I
expand the "views" in Sql Management Studio object browser I get an error
that says "Parameter cannot be null" and none of the objects are there!!!
All other object types seem fine and only this database exhibits this
behavior. I'm not sure how to track this down.the error message is actually this
Value cannot be null.
Parameter name: context (ObjectExplorer)
"Tim Greenwood" <tim_greenwood A-T yahoo D-O-T com> wrote in message
news:%23QwU%23MMaGHA.4788@.TK2MSFTNGP02.phx.gbl...
> We are supposed to be deploying to SQL2K5 this friday night. I've been
> taking backups from our SQL 2K server and restoring them directly on our
> 2K5 box. Everything seems to work ok except for one of our databases.
> When I expand the "views" in Sql Management Studio object browser I get an
> error that says "Parameter cannot be null" and none of the objects are
> there!!! All other object types seem fine and only this database exhibits
> this behavior. I'm not sure how to track this down.
>|||One thing that I know doesn't work in 2005 is databases in a too low compatibility mode (60 and 65,
I believe). I'd think that SSMS would give a better error message, but worth looking into.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Tim Greenwood" <tim_greenwood A-T yahoo D-O-T com> wrote in message
news:%23dtxLQMaGHA.3304@.TK2MSFTNGP04.phx.gbl...
> the error message is actually this
> Value cannot be null.
> Parameter name: context (ObjectExplorer)
> "Tim Greenwood" <tim_greenwood A-T yahoo D-O-T com> wrote in message
> news:%23QwU%23MMaGHA.4788@.TK2MSFTNGP02.phx.gbl...
>> We are supposed to be deploying to SQL2K5 this friday night. I've been taking backups from our
>> SQL 2K server and restoring them directly on our 2K5 box. Everything seems to work ok except for
>> one of our databases. When I expand the "views" in Sql Management Studio object browser I get an
>> error that says "Parameter cannot be null" and none of the objects are there!!! All other object
>> types seem fine and only this database exhibits this behavior. I'm not sure how to track this
>> down.
>|||And what if you query sys.objects? Are the object listed in
the catalog view? Or in the information_schema.views view?
I've hit a few flaky things like that with SSMS. Usually
when I hit the bug with the index error in SSMS, I start
seeing other object display issues until I close SSMS and
reopen. I think some, most of those are fixed in SP1 for SQL
2005.
-Sue
On Tue, 25 Apr 2006 16:51:57 -0700, "Tim Greenwood"
<tim_greenwood A-T yahoo D-O-T com> wrote:
>We are supposed to be deploying to SQL2K5 this friday night. I've been
>taking backups from our SQL 2K server and restoring them directly on our 2K5
>box. Everything seems to work ok except for one of our databases. When I
>expand the "views" in Sql Management Studio object browser I get an error
>that says "Parameter cannot be null" and none of the objects are there!!!
>All other object types seem fine and only this database exhibits this
>behavior. I'm not sure how to track this down.
>