sqldatasource problems

  • Thread starter Thread starter zapov
  • Start date Start date
Z

zapov

Hi!

Did anyone successfully managed to use some custom ADO.NET
provider with SqlDataSource? I'd like to connect to some
other database than MSSQL (like MySQL, Firebird or PostgreSQL)
but I'm having problems making this work.
Inside connectionStrings I added my name, provider and
connectionString but for some reason SqlDataSource is trying
to use System.Data.SqlClient even if my provider is
different.

Also I tried registering my provider in machine.config but it
won't show up in VS.

Any help would be appreciated.
 
Bruce said:
what driver did you specify in the connect string?

I'm using PostgreSQL driver.
In Web.config I added
<add name="postgres" connectionString="server=localhost;User
id=postgres;Password=1234;database=proba;Encoding=Unicode"
providerName="Npgsql" />

And in aspx file I have
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:postgres %>"
SelectCommand="select * from table"></asp:SqlDataSource>

But, when I try to run it I get
Keyword not supported: 'encoding'.
because ASP is trying to use System.Data.SqlClient
[ArgumentException: Keyword not supported: 'encoding'.]
System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable
parsetable, String connectionString, Boolean buildChain, Hashtable
synonyms, Boolean firstKey) +263
System.Data.Common.DbConnectionOptions..ctor(String
connectionString, Hashtable synonyms, Boolean useOdbcRules) +129
System.Data.SqlClient.SqlConnectionString..ctor(String
connectionString) +116

System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String
connectionString, DbConnectionOptions previous) +46

System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(String
connectionString, DbConnectionPoolGroupOptions poolOptions,
DbConnectionOptions& userConnectionOptions) +201
System.Data.SqlClient.SqlConnection.ConnectionString_Set(String
value) +82
System.Data.SqlClient.SqlConnection.set_ConnectionString(String
value) +28
System.Web.UI.WebControls.SqlDataSource.CreateConnection(String
connectionString) +63

System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments
arguments) +215
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments
arguments, DataSourceViewSelectCallback callback) +84
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +154
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +99
System.Web.UI.WebControls.GridView.DataBind() +24
 
zapov said:
I'm using PostgreSQL driver.
In Web.config I added
<add name="postgres" connectionString="server=localhost;User
id=postgres;Password=1234;database=proba;Encoding=Unicode"
providerName="Npgsql" />

And in aspx file I have
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:postgres %>"
SelectCommand="select * from table"></asp:SqlDataSource>

Also, when I change SqlDataSource to
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:postgres %>"
ProviderName="<%$ ConnectionStrings:postgres.providerName %>"
SelectCommand="select * from bugs.bugs"></asp:SqlDataSource>

I receive
Failed to find or load the registered .Net Framework Data Provider.

[ConfigurationErrorsException: Failed to find or load the registered
..Net Framework Data Provider.]
System.Data.Common.DbProviderFactories.GetFactory(DataRow
providerRow) +371
System.Data.Common.DbProviderFactories.GetFactory(String
providerInvariantName) +138
System.Web.UI.WebControls.SqlDataSource.GetDbProviderFactory() +64
System.Web.UI.WebControls.SqlDataSource.GetDbProviderFactorySecure() +51
System.Web.UI.WebControls.SqlDataSource.CreateConnection(String
connectionString) +37


Ok, I get it. ASP can't find registered DbProviderFactory
But, I have in machine.config under <DbProviderFactories>
<add name="PostgreSQL Data Provider" invariant="Npgsql"
description=".Net Framework Data Provider for PostgreSQL"
type="Npgsql.NpgsqlFactory, System.Data, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" />

And as I understand this should enable it to be displayed in VS
but it isn't.

So, I am wondering is there anything special that should be
implemented in ADO.NET provider so it could be used in SqlDataSource?
 
Back
Top