0

I have a webapplication that only for saving a uploadded video file's path to the sqlserver database.i have a bussiness logicslayer in the application.

I am using asp.net/vb.net. I put this in the bll for connecting with stored procedure,

 Dim Db As Database = DatabaseFactory.CreateDatabase()

there is a error that--

object reference not set to an instance of an object

if any one knows please help me.

Here is the stack trace:

[NullReferenceException: Object reference not set to an instance of an object.]
Microsoft.Practices.EnterpriseLibrary.Data.DatabaseConfigurationView.get_DefaultName() +38
Microsoft.Practices.EnterpriseLibrary.Data.DatabaseMapper.MapName(String name, IConfigurationSource configSource) +65
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationNameMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id) +122
Microsoft.Practices.ObjectBuilder.BuilderBase`1.DoBuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies) +316
Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies) +168
Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, String idToBuild, Object existing, PolicyList[] transientPolicies) +104
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp(IReadWriteLocator locator, IConfigurationSource configurationSource) +228
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp(IConfigurationSource configurationSource) +65
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.NameTypeFactoryBase`1.CreateDefault() +72
Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.CreateDatabase() +86
Uploader.BllUpdate.SaveFileDetails() in D:\Developers\Sinoy\uploader\Uploader\Uploader\BLL\BllUpdate.vb:37
Uploader.Upload.UploadBtn_Click(Object sender, EventArgs e) in D:\Developers\Sinoy\uploader\Uploader\Uploader\Forms\Upload.aspx.vb:17
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102
Santosh Panda
  • 6,873
  • 8
  • 40
  • 54
user85511
  • 375
  • 6
  • 11
  • 25
  • Tag your question with the technology used. That looks like it might be visual basic, but I don't know what kind. You won't get an answer as it currently is. – Paul McMillan Oct 29 '09 at 05:23
  • possible duplicate of [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Ňɏssa Pøngjǣrdenlarp Oct 15 '14 at 22:25

5 Answers5

0

Did you check your web.config? Have you set the Database connection string properly? This issue also happens when your connection string is missing or not proper.

Karthik B S
  • 21
  • 1
  • 3
0

object reference not set to an instance of object means that there is a reference which wasnt instantiated before it was used. The reference is still null (or in VB lingo, Nothing).

Catch the exception and check the stack trace on where it occured.

Andrew Keith
  • 7,222
  • 1
  • 22
  • 39
0

Usually when you get that error it is because an class variable (such as DatabaseFactory or a variable inside that class) is used before it has been assigned an instance of the class, as with the New keyword in the Dim statement or assignment. There are other ways to assign instances to a variable, too. If you don't, you'll get this error message.

xpda
  • 15,014
  • 8
  • 47
  • 78
0

The call into the Microsoft Enterprise Library static method DatabaseFactory.CreateDatabase is causing something inside the Microsoft Enterprise Library to crash - it's using a variable that has no value (it is Nothing). For some reason it is unable to connect to your database. Why it doesn't throw a more informative exception I don't know - you'd have to ask Microsoft.

I know nothing about the Enterprise Library, but I think I'd check your web.config or app.config configuration settings looking at the database connection strings for the default database. This is based on a 5 second skim-read of the documentation and some Googling of online forums.

MarkJ
  • 29,252
  • 4
  • 60
  • 104
0

First, make sure you set the default database, i.e.

Also, if it is a virtual directory, make sure your Web.config file inside that virtual directory does not get overridden by the root directoriy's Web.config EnterpriseLibrary related elements.

Max Kramnik
  • 189
  • 1
  • 8