locked
Specifying provider name within C# class RRS feed

  • Question

  • User1503923713 posted

    I am adapting a book example of a shopping cart application, and have almost, got it complety working. I am using an access database rather than a sql server one used in the example. Earlier on I found I had an issue with the sql datasource where I had to specify the provider name as below of I would get the error about provider keyname not being supported

    ConnectionString

    ="<%$ ConnectionStrings:OICConnectString %>"

    ProviderName

    ="System.Data.OleDb"

     

    Now, within once of the classes, it refers to the database connection string and this is now where the same error occurs, when the page requires this class and it must be because the provider name is not specified, but i'm new to C# so I'm not sure how to do it. Here is this part of the class

     

    public static bool WriteOrder(Order o)

    {

    string cs = WebConfigurationManager

    .ConnectionStrings["OICConnectString"]//the connection string name

    .ConnectionString;

    con = new SqlConnection(cs);

    con.Open();

    tran = con.BeginTransaction();

     

     

     

     

     

    Thursday, April 8, 2010 2:50 PM

Answers

  • User-821857111 posted

    con = new SqlConnection(cs);

    You need to change that to new OleDbConnection. You'll find the same thing if you have references to SqlCommand (becomes OleDbCommand), SqlDataReader (becomes OleDbDataReader) etc.

    It's because with Sql Server, you use the Stsrem.Data.SqlClient classes, whereas with Jet (Access), it's System.Data.OleDb.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 8, 2010 3:16 PM

All replies

  • User-821857111 posted

    con = new SqlConnection(cs);

    You need to change that to new OleDbConnection. You'll find the same thing if you have references to SqlCommand (becomes OleDbCommand), SqlDataReader (becomes OleDbDataReader) etc.

    It's because with Sql Server, you use the Stsrem.Data.SqlClient classes, whereas with Jet (Access), it's System.Data.OleDb.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 8, 2010 3:16 PM
  • User1503923713 posted

    Ok, I changed it, but now I get the error :

    CS0246: The type or namespace name 'OleDbConnection' could not be found (are you missing a using directive or an assembly reference?)
     

    Thursday, April 8, 2010 3:51 PM
  • User1503923713 posted

    Ok, I solved it, I had to change settings in visual web developer to use the right provider, by right clicking and it works now, thanks 

    Thursday, April 8, 2010 3:55 PM