TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
BLove
NA
3
0
Help with Activator.CreateInstance for DB Provider
Nov 16 2007 6:41 PM
I followed the Activator.CreateInstance method but I can't get this core piece to work. I have a MSAccess db provider for testing purposes but keep getting a compiling error. Can someone help me as to what I'm doing wrong?
namespace Company.DAL
{
public abstract class ConfigProvider : DataAccess
{
static private ConfigProvider _instance = null;
static public ConfigProvider Instance
{
get
{
if (_instance == null)
_instance = (ConfigProvider)Activator.CreateInstance(
Type.GetType(Company.DAL.MdbClient.MdbConfig));
return _instance;
}
}
public abstract string GetConfigValue(ConfigXML site, string id, string name);
}
}
Then in the "interchangable" data access layer I have this:
namespace Company.DAL.MdbClient
{
public class MdbConfig : ConfigProvider
{
public override string GetConfigValue(ConfigXML site, string id, string name)
{
try
{
string connString = WebConfigurationManager.ConnectionStrings[site.SettingsTable.ConnectionStringName].ConnectionString;
string sqlCmd = "SELECT Value FROM " + site.SettingsTable.TableName + " WHERE UCASE(id)='" + id.ToUpper() + "' AND UCASE(name)='" + name.ToUpper() + "'";
using (OleDbConnection conn = new OleDbConnection(connString))
{
OleDbCommand cmd = new OleDbCommand(sqlCmd, conn);
conn.Open();
object obj = cmd.ExecuteScalar();
if (obj.Equals(System.DBNull.Value))
return string.Empty;
else
return (string)obj;
}
}
catch
{
return string.Empty;
}
}
}
}
Then in my aspx page I'm calling the method like this:
Response.Write(ConfigProvider.Instance.GetConfigValue(domain, "company", "Address1"));
But I get this error:
Compiler Error Message: CS0119: 'Company.DAL.MdbClient.MdbConfig' is a 'type', which is not valid in the given context
Source Error:
Line 21: if (_instance == null)
Line 22: _instance = (ConfigProvider)Activator.CreateInstance(
Line 23: Type.GetType(Company.DAL.MdbClient.MdbConfig));
Line 24: return _instance;
Line 25: }
Reply
Answers (
1
)
Comparing several XML feeds
Tracking Data one aspx page to another aspx page using Gridview