0

I would like to use Dapper to establish a link for my WebApi. But I got this error below:

The value's length for key 'data source' exceeds it's limit of '128'

The cause of this error is this line:

IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);

Below is my connection string in the Web.config:

<connectionStrings>    
   <add name="DefaultConnection"
         connectionString="Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=myService)));User ID=userId;Password=password"
         providerName="System.Data.OracleClient"/>   
</connectionStrings>

I know there is a way to solve this by using Oracle.ManagedDataAccess but I would really like to try using Dapper. Is there a way where I can solve the limit issue?

I have looked at this solution The value's length for key 'data source' exceeds it's limit of '128' but is there a simpler way without involving Oracle.ManagedDataAccess? Thanks

Intan
  • 15
  • 1
  • 8
  • Possible duplicate of [The value's length for key 'data source' exceeds it's limit of '128'](https://stackoverflow.com/questions/37282108/the-values-length-for-key-data-source-exceeds-its-limit-of-128) – Rai Vu Feb 06 '18 at 07:22
  • Why SqlConnection for Oracle? – Adriano Repetti Feb 06 '18 at 07:28
  • I followed this example https://www.jeremymorgan.com/blog/programming/how-to-dapper-web-api/ . Should I change it ? – Intan Feb 06 '18 at 07:30
  • It's for MsSql then yes, you should change it (but not sure if it will also solve your current problem, maybe) – Adriano Repetti Feb 06 '18 at 07:37
  • That solved the issue. Thank you so much. – Intan Feb 06 '18 at 07:47
  • Provider `System.Data.OracleClient` is [deprecated](https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/oracle-and-adonet) for ages. You should not use it anymore. – Wernfried Domscheit Feb 06 '18 at 09:56

1 Answers1

0

I have changed the SqlConnection to OracleConnection and it solved the issue.

using System.Data.OracleClient;
....

IDbConnection db = new OracleConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
Intan
  • 15
  • 1
  • 8