SQL Server 2005 Express connection error?

J

jnikle

When I run the code below in Visual Web Developer 2005 Express, I'm
getting an "Unable to find the requested .Net Framework Data Provider.
It may not be installed." error. I've been researching a fix for the
past two days without any luck. I've tried completely uninstalling
both VWD and SQL Server 2005 Express and reinstalling. I've checked
for capitalization and typos (code compiles fine). I've also looked at
the machine.config file, although I really don't know what I'm looking
for to be honest. There are lines in there for
"System.Data.SQLClient," although they don't use the same
capitalization.

Anyone out there seen this issue before and have a fix? If not, can
someone enlighten me as to how to troubleshoot it? I'm just beginning
in C# and SQL Server, so any info would be greatly appreciated.

Anyway, here's the code that's throwing the error. It's the
"DbProviderFactory factory =
DbProviderFactories.GetFactory(dataProviderName);" line.

public static DbCommand CreateCommand()
{
//Obtain the database provider name
string dataProviderName =
MyProjectConfiguration.DbProviderName;
//Obtain the database connection string
string connectionString =
MyProjectConfiguration.DbConnectionString;
//Create a new data provider factory
DbProviderFactory factory =
DbProviderFactories.GetFactory(dataProviderName);
//Obtain a database specific connection object
DbConnection conn = factory.CreateConnection();
//Set the connection string
conn.ConnectionString = connectionString;
//Create a database specific command object
DbCommand comm = conn.CreateCommand();
//Set the command type to stored procedure
comm.CommandType = CommandType.StoredProcedure;
//Return the initialized command object
return comm;
}

-Josh Nikle
 
G

Guest

sperhap you did not use the key word imports (using in C#)
System.Data.SQLClient prior to the beginning of your class. This allows u to
have access to the members of that class. I hope u find this helpfull. In
vb.net we use the key word imports.
 
J

jnikle

Unfortunately, that didn't do the trick. Thanks for the suggestion
though. Any other thoughts?

-Josh
 
G

Guest

Josh,

What provider is specified in MyProjectConfiguration.DbProviderName?

What connection string is specified in
MyProjectConfiguration.DbConnectionString?

Kerry Moorman
 
J

jnikle

Kerry-

In my Web.Config file:

<connectionStrings>
<add name="MyProjectConnection"
connectionString="Server=(local)\SqlExpress;Integrated
Security=True;Database=MyDatabase" providerName="System.Data.SQLClient"
/>
</connectionStrings>


In my MyProjectConfiguration class:

static MyProjectConfiguration()
{
dbConnectionString =
ConfigurationManager.ConnectionStrings["MyProjectConnection"].ConnectionString;
dbProviderName =
ConfigurationManager.ConnectionStrings["MyProjectConnection"].ProviderName;
}

-Josh
 
W

William \(Bill\) Vaughn

I have seen this before. When accessing some of the providers in the table,
I got that exception--I simply stepped over the provider. I posted code on
my blog that illustrates this.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
G

Guest

Josh,

I would try a couple of things at this point:

1. Hard-code the provider and connection string and see if that works. If
it does, then the problem is getting the provider and connection string
information from the config files.

2. Use a message box or some other debugging display technique to see what
you are actually retrieving for the provider name and the connection string.

Kerry Moorman


Kerry-

In my Web.Config file:

<connectionStrings>
<add name="MyProjectConnection"
connectionString="Server=(local)\SqlExpress;Integrated
Security=True;Database=MyDatabase" providerName="System.Data.SQLClient"
/>
</connectionStrings>


In my MyProjectConfiguration class:

static MyProjectConfiguration()
{
dbConnectionString =
ConfigurationManager.ConnectionStrings["MyProjectConnection"].ConnectionString;
dbProviderName =
ConfigurationManager.ConnectionStrings["MyProjectConnection"].ProviderName;
}

-Josh



Kerry said:
Josh,

What provider is specified in MyProjectConfiguration.DbProviderName?

What connection string is specified in
MyProjectConfiguration.DbConnectionString?

Kerry Moorman
 
J

jnikle

Kerry-

Thanks!

Per your suggestion, I stepped into my code, and the connectionString
and providerName variables were getting the correct values. Well, they
were getting the values I set in my Web.Config file anyway. ;) What I
ended up doing to solve the problem is change the connection string to
"(local)\\SQLEXPRESS" instead of "(local)\SQLEXPRESS." Works like a
charm now.

Just for my own benefit, what's the difference between one and two back
slashes?

-Josh
 
J

jnikle

Well, nevermind. Forgot to undo hardcoding of the provider and
connection string before my last post. When I change back to using a
variable, the error returns. When I look the the variable's value,
it's showing "System.Data.SQLClient," which is exactly what I
hardcoded, but it still won't work.

Any other suggestions?

-Josh
 

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

Top