Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public static DbCommand CreateCommand()
{ 
            //WebConfigReader 
            // Obtain the database provider name
            string dataProviderName = WebConfigReader.DbProviderName;
            // Obtain the database connection string
            string connectionString = WebConfigReader.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;
        }
    }
}


What I have tried:

i tried to change dbprovider name and connection string how to fix
Posted
Updated 11-Jan-18 6:39am
v2

Look at the error message:
Value cannot be null.
parameter name: providerinvariantname

That is coming from your DB and means that you are trying to insert or update a column with a null value on a column declared as NOT NULL.

We can't fix that: it's your DB, and your data! Either nulls are allowed - in which case change your DB - or they aren't - in which case sanitize your data inputs.
We can't do any of that for you...
 
Share this answer
 
Comments
Richard Deeming 11-Jan-18 12:38pm    
Are you sure about that? :)

As far as I can see, the error is coming from the DbProviderFactories.GetFactory method, not the database. It would suggest that WebConfigReader.DbProviderName (whatever that is) is returning null for some reason.
The error message would suggest that WebConfigReader.DbProviderName is returning null. You'll need to debug your code to find out why.
 
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