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="BalloonShopConnection" connectionString="server=TAPAN-PC;Database=BallonShop;User=ballonshop;Password=ecommerce" 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(DbCommand 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.DbProviderName;

        //Obtain the database connection string
        string connectionString = BalloonShopConfiguration.DbConnectionString;
         
        //Create a new data Provider Factroy
        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 procecures
        comm.CommandType = CommandType.StoredProcedure;

        //Return the initialized command object
        return comm;

    }
}

GenericDataAccess1.JPG
LVL 22
Tapan PattanaikSenior EngineerAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Alfred A.Connect With a Mentor Commented:
Hi,

What is the exact error displayed if you inspect ex.Message, ex.Source, and ex.StackTrace?  Can you provide that information?
0
 
Tapan PattanaikSenior EngineerAuthor Commented:
When i build the solution (F6). it tells  build succeed, but when i press F5 ,it redirects to the  "App_Code\GenericDataAccess.cs" file. Screen shot of  which i was attached previously and i was also posted full code of that page  in my question.

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
0
 
Tapan PattanaikSenior EngineerAuthor Commented:
Please check the exact error message.


ErrrorMesage.JPG
0
 
Tapan PattanaikSenior EngineerAuthor Commented:
From StackTrace i found  the error was in connection string. I was writing wrong " ProviderName" instead of "providerName".

0
All Courses

From novice to tech pro — start learning today.