Tapan Pattanaik
asked on
Error in web.config file and dataaccess
hi Experts,
I am using asp.net, C# , SQL SERVER. In my web.config file I am using ProviderName= "System.Data.SqlClient", but in my data access i am using dbProvider, when i execute i got the error. I have attached screen shot for your review. I guess the error is in between web.config and my dataAccess. Please let me know.
============////////////// //////==== ========== =///////// ////////// /
<connectionStrings>
<add name="BalloonShopConnectio n" connectionString="server=T APAN-PC;Da tabase=Bal lonShop;Us er=ballons hop;Passwo rd=ecommer ce" ProviderName="System.Data. SqlClient" />
</connectionStrings>
========================== ========== ========== ==========
using System;
using System.Collections.Generic ;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.Common;
/// <summary>
/// Class contains generic data access functionality to be accessed from the businesstier
/// </summary>
public static class GenericDataAccess
{
//static constructor
static GenericDataAccess()
{
}
//Execute a command and returns the results as a dataTable object
public static DataTable ExecuteSelectCommand(DbCom mand command )
{
//The DataTable to be returned
DataTable table;
// Execute the command,making sure the connection gets closed in the end
try
{
//Open the data connection
command.Connection.Open();
//Execute the command and save the results in a DataTable
DbDataReader reader = command.ExecuteReader();
table = new DataTable();
table.Load(reader);
//Close the connection
reader.Close();
}
catch (Exception ex)
{
Utilities.LogError(ex);
throw;
}
finally
{
//close the connection
command.Connection.Close() ;
}
return table;
}
//Create and prepares a new Dbcommand object on a new connection
public static DbCommand CreateCommand()
{
//obtain the database provider name;
string dataProviderName = BalloonShopConfiguration.D bProviderN ame;
//Obtain the database connection string
string connectionString = BalloonShopConfiguration.D bConnectio nString;
//Create a new data Provider Factroy
DbProviderFactory factory= DbProviderFactories.GetFac tory(dataP roviderNam e);
// 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 procecures
comm.CommandType = CommandType.StoredProcedur e;
//Return the initialized command object
return comm;
}
}
GenericDataAccess1.JPG
I am using asp.net, C# , SQL SERVER. In my web.config file I am using ProviderName= "System.Data.SqlClient", but in my data access i am using dbProvider, when i execute i got the error. I have attached screen shot for your review. I guess the error is in between web.config and my dataAccess. Please let me know.
============//////////////
<connectionStrings>
<add name="BalloonShopConnectio
</connectionStrings>
==========================
using System;
using System.Collections.Generic
using System.Linq;
using System.Web;
using System.Data;
using System.Data.Common;
/// <summary>
/// Class contains generic data access functionality to be accessed from the businesstier
/// </summary>
public static class GenericDataAccess
{
//static constructor
static GenericDataAccess()
{
}
//Execute a command and returns the results as a dataTable object
public static DataTable ExecuteSelectCommand(DbCom
{
//The DataTable to be returned
DataTable table;
// Execute the command,making sure the connection gets closed in the end
try
{
//Open the data connection
command.Connection.Open();
//Execute the command and save the results in a DataTable
DbDataReader reader = command.ExecuteReader();
table = new DataTable();
table.Load(reader);
//Close the connection
reader.Close();
}
catch (Exception ex)
{
Utilities.LogError(ex);
throw;
}
finally
{
//close the connection
command.Connection.Close()
}
return table;
}
//Create and prepares a new Dbcommand object on a new connection
public static DbCommand CreateCommand()
{
//obtain the database provider name;
string dataProviderName = BalloonShopConfiguration.D
//Obtain the database connection string
string connectionString = BalloonShopConfiguration.D
//Create a new data Provider Factroy
DbProviderFactory factory= DbProviderFactories.GetFac
// 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 procecures
comm.CommandType = CommandType.StoredProcedur
//Return the initialized command object
return comm;
}
}
GenericDataAccess1.JPG
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ASKER
From StackTrace i found the error was in connection string. I was writing wrong " ProviderName" instead of "providerName".
ASKER
In the web browser i have seen this error. which i have attached screen shot below for your review.
<if you want to check my ConnectionString , you can check in my question which i have posted first.>
Thanks,
tapan Pattanaik.
Error-in-webpage.JPG