Click here to Skip to main content
15,910,009 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,I write 3 tier program like this link http://geekswithblogs.net/edison/archive/2009/04/05/a-simple-3-tier-layers-application-in-asp.net.aspx[^]
but when I run this an error occured at below line on GenericData.cs and says dbProviderName caacon be null! what should I do?help me plz,it's an emergency :-(
C#
DbProviderFactory factory = DbProviderFactories.GetFactory(dbProviderName);

[Edit]Code block added[/Edit]
Posted
Updated 9-Mar-13 3:16am
v2
Comments
Anurag Sinha V 9-Mar-13 2:48am    
hi i guess u r havin problems wd your connection string..can u post ur code as to what have you done in your connection string??
behish 9-Mar-13 3:44am    
here is my web.config code<configuration> <connectionstrings> <add name="ConnectionString" providername="System.Data.SqlClient" connectionstring="Data Source=.;Initial Catalog=sampleDB;Integrated Security=True;Pooling=False">"

<system.data> <dbproviderfactories> <add description=".Net Framework Data Provider for SqlServer" type="System.Data.SqlClient.SqlClientFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="Sql Client DataProvider" invaiant="System.Data.SqlClient">

<system.web> <compilation targetframework="4.0" debug="true">
behish 9-Mar-13 3:52am    
and here is my configuration.cs code:
namespace SConfiguration
{
public class Configuration
{

private static string dbConnectrionString;
private static string dbProviderName;
public Configuration()
{
dbConnectrionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
dbProviderName = ConfigurationManager.ConnectionStrings["ConnectionString"].ProviderName;

}
public static string DBConnectionString
{
get { return dbConnectrionString; }
}
public static string DBProviderName
{
get { return dbProviderName; }
}

}
behish 9-Mar-13 3:54am    
here is my genericData.cs class:
public class GenericData
{
public GenericData()
{
}
public static DataTable ExecuteReader(DbCommand Command)
{
DataTable table;
try
{
Command.Connection.Open();
DbDataReader reader = Command.ExecuteReader();
table = new DataTable();
table.Load(reader);
}
catch (Exception ex)
{ throw ex; }
finally
{ Command.Connection.Close(); }
return table;
}

public static DbCommand CreateCommand()
{
string dbProviderName = Configuration.DBProviderName;
string dbConnectionString = Configuration.DBConnectionString;
DbProviderFactory factory = DbProviderFactories.GetFactory(dbProviderName);
DbConnection Connection = factory.CreateConnection();
Connection.ConnectionString = dbConnectionString;
DbCommand command = Connection.CreateCommand();
command.CommandType = CommandType.StoredProcedure;
return command;
}
Anurag Sinha V 9-Mar-13 9:10am    
hi...i guess you can just define your connection string in a normal way...
<connectionstrings>
<add name="conn" connectionstring="Data Source=DEVELOPER-PC; Initial Catalog=Development; Integrated security=true" providername="System.Data.SqlClient">

you were trying to retrieve the providerName via the code they have given in the website..i don't see the necessity of it...try to give the connection string as above and remove the dbprovidername code from your total code and it should work...try it

-anurag

When you take code from a website and it doesn't work, where do you think you should address any questions? The site that wrote the code and knows it inside out, or a totally unrelated site that probably knowns as much about it as your do, and would have to look?

Ask them first.
If they don't help you (which is unlikely) then ask here, but not just by posting a link to their code - we do not know how much of it you used, so a relentless fragment from your actual program would be of more use...
 
Share this answer
 
Comments
behish 9-Mar-13 3:47am    
I also ask in particular website but they didn't answer me.I wrote all the codes just like sample But I don't know where is my problem?
OriginalGriff 9-Mar-13 3:59am    
How long did you give them? They probably aren't sitting there waiting for you! FOr example, it is a Saturday here, so few people are at work or even out of bed yet! :laugh:
Richard MacCutchan 9-Mar-13 4:26am    
Hey, I'm up, and I made the tea. :)
OriginalGriff 9-Mar-13 4:32am    
:laugh:
Bets on DD having surfaced yet? Nagy has no choice: the Ickles will ensure it... ;)
XML
<connectionStrings>
    <add name="conn" connectionString="Data Source=DEVELOPER-PC; Initial Catalog=Development; Integrated security=true" providerName="System.Data.SqlClient"/>
</connectionStrings>



try it..it should work..

regards
anurag
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900