VBBRett
asked on
Object Reference not set to an Instance of an Object
I am writing C# code for a Sharepoint solution and I thought I declared as an instance of an object and I still get the error. Here is my code...I tend to get an error on the line where it has the code hillContentDB.Server.Name = "";....what am I doing wrong? :
SPServer HillSPServer = new SPServer();
HillSPServer.Name = dbserver;
HillSpDatabase hillContentDB = new HillSpDatabase();
hillContentDB.Server.Name = "";
hillContentDB.Name = "";
hillContentDB.Server.Name = HillSPServer.Name;
hillContentDB.Name = dbname;
SPServer HillSPServer = new SPServer();
HillSPServer.Name = dbserver;
HillSpDatabase hillContentDB = new HillSpDatabase();
hillContentDB.Server.Name = "";
hillContentDB.Name = "";
hillContentDB.Server.Name = HillSPServer.Name;
hillContentDB.Name = dbname;
where does this get instantiated? most likely the name server property is null at that point.
by this i mean
hillContentDB...
sorry
hillContentDB...
sorry
ASKER
how can I instantiate hillContentDB? I made a derived class of a SPContentDB class from Sharepoint. So, what I have is the following in the derived class:
using System;
using System.Collections.Generic ;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Admin istration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls. WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebCo ntrols;
using System.Collections.Generic ;
using System.Data;
using System.Security;
using Microsoft.SharePoint.Admin istration. AccessCont rol;
namespace SiteCreateVisualWebPartSol ution.Visu alWebPart1
{
class HillSpDatabase: SPDatabase
{
static void Main()
{
SPDatabase dBase = new SPDatabase();
}
public void GrantAccess(System.Securit y.Principa l.Security Identifier securitykey)
{
base.GrantAccess(securityk ey);
}
}
}
using System;
using System.Collections.Generic
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Admin
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebCo
using System.Collections.Generic
using System.Data;
using System.Security;
using Microsoft.SharePoint.Admin
namespace SiteCreateVisualWebPartSol
{
class HillSpDatabase: SPDatabase
{
static void Main()
{
SPDatabase dBase = new SPDatabase();
}
public void GrantAccess(System.Securit
{
base.GrantAccess(securityk
}
}
}
Can't find any Server property in your HillSPDatabase class, is it a part of SPDatabase, if yes can we set empty string to Name as you have done...
where the code for Server property and its Name Property's Set Method and how does they behave....
where the code for Server property and its Name Property's Set Method and how does they behave....
ASKER
HillSPDatabase class is derived from SPDatabase Sharepoint class. The reason why I derived the SPDatabase class with HillSPDatabase class is because I wanted to be able to use the adduser protected method from SPDatabase class. Are you wanting me to set the string name to empty in the HillSPDatabase class or in the code where I declare the HillSPDatabase variable as HillContentDB?
you are using default constructor of SPDatabase. As your class contains no constructor, it will automatically call base class's Default constructor.
This doesn't set the Server(SPServer type) property.
You need to use the one with SPDatabaseParameters option.
See Here:-
Seems that The Server Property of SPDatabase is null, reason why it is giving you object reference not set.. error...
This doesn't set the Server(SPServer type) property.
You need to use the one with SPDatabaseParameters option.
See Here:-
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spdatabase.spdatabase.aspx
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spdatabaseparameters_members.aspx
Seems that The Server Property of SPDatabase is null, reason why it is giving you object reference not set.. error...
ASKER
so what do I do? Can you tell me where in my code I should change or correct?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I added the following to my base HillSpdatabase class:
public HillSpDatabase();
public HillSpDatabase(SPDatabaseP arameters parameters);
public HillSpDatabase(string name, SPDatabaseServiceInstance serviceInstance);
so now my class looks like the following...
using System;
using System.Collections.Generic ;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Admin istration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls. WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebCo ntrols;
using System.Collections.Generic ;
using System.Data;
using System.Security;
using Microsoft.SharePoint.Admin istration. AccessCont rol;
namespace SiteCreateVisualWebPartSol ution.Visu alWebPart1
{
class HillSpDatabase: SPDatabase
{
static void Main()
{
SPDatabase dBase = new SPDatabase();
}
public HillSpDatabase();
public HillSpDatabase(SPDatabaseP arameters parameters);
public HillSpDatabase(string name, SPDatabaseServiceInstance serviceInstance);
public void GrantAccess(System.Securit y.Principa l.Security Identifier securitykey)
{
base.GrantAccess(securityk ey);
}
}
}
public HillSpDatabase();
public HillSpDatabase(SPDatabaseP
public HillSpDatabase(string name, SPDatabaseServiceInstance serviceInstance);
so now my class looks like the following...
using System;
using System.Collections.Generic
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Admin
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebCo
using System.Collections.Generic
using System.Data;
using System.Security;
using Microsoft.SharePoint.Admin
namespace SiteCreateVisualWebPartSol
{
class HillSpDatabase: SPDatabase
{
static void Main()
{
SPDatabase dBase = new SPDatabase();
}
public HillSpDatabase();
public HillSpDatabase(SPDatabaseP
public HillSpDatabase(string name, SPDatabaseServiceInstance serviceInstance);
public void GrantAccess(System.Securit
{
base.GrantAccess(securityk
}
}
}
looks ok, just use constructors with parameters, supply the values and it will work fine, trust me....
ASKER
I never worked with SPDatabaseParameters type before. So say I want to pass the following parameters:
server name = srv1
datbase name = dbn1
userid = dbcreator
password = pass123!
How would I pass these parameters to the SPDatabaseParameters so that it is able to use the parameter?
server name = srv1
datbase name = dbn1
userid = dbcreator
password = pass123!
How would I pass these parameters to the SPDatabaseParameters so that it is able to use the parameter?
ASKER
How would I pass the parameter strings, I'm not sure how it works?