No extension method called open in ServiceStack.Data.IDbConnectionFactory

367 views Asked by At

I wanted use servicestack.ormlite to connect to the database.But I get this error even after adding the refrence from Nuget.

I used this command to install

Install-Package ServiceStack.OrmLite.SqlServer

This is the error thrown

'ServiceStack.Data.IDbConnectionFactory' does not contain a definition for 'Open' and no extension method 'Open' accepting a first argument of type 'ServiceStack.Data.IDbConnectionFactory' could be found (are you missing a using directive or an assembly reference?)

var dbFactory = new OrmLiteConnectionFactory(connectionString, SqliteDialect.Provider);
//I get error when I call open method
using (IDbConnection db = dbFactory.Open())
{

}
2

There are 2 answers

0
mythz On BEST ANSWER

The IDbConnectionFactory.Open() extension method is defined in OrmLiteConnectionFactoryExtensions that's defined under ServiceStack.OrmLite namespace so you need to import:

using ServiceStack.OrmLite;
2
Chetan On

Are you sure that Extension method Open does not take any argument?

I checked the source code of OrmLiteConnectionFactory Extensions on git and there is no extension method with name Open for OrmLiteConnectionFactory which take no argument. Extension method Open of OrmLiteConnectionFactory takes one string argument "nammedconnection".

Following is the git link of the source code. https://github.com/ServiceStack/ServiceStack.OrmLite/blob/master/src/ServiceStack.OrmLite/OrmLiteConnectionFactory.cs

So I am sure calling Open with proper argument would resolve your issue.

Thanks and regards, Chetan Ranpariya