配置ASP.NET开发服务器连接到一个Postgres数据库 [英] Configuring ASP.NET Development Server to connect to a postgres database

查看:792
本文介绍了配置ASP.NET开发服务器连接到一个Postgres数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有被配置为连接到MS SQL Server数据库的现有ASP.NET应用程序,我试图修改它使用Postgres数据库来代替。

我想避免修改C#code,如果可能的话。

我预计,以下变化就足够了:


  1. 添加一个引用到一个合适的Postgres驱动程序,在这种情况下 NauckIT.PostgreSQLProvider.dll

  2. 添加提供商标记来指定驱动程序使用,在这种情况下:


   <&是connectionStrings GT;
     <添加名称=默认的connectionString =服务器= 127.0.0.1,端口= 5432;用户ID = finnw;密码= XXX;数据库=默认值;池=假
       的providerName =Npgsql的/>   < /&是connectionStrings GT;

的providerName 标记似乎没有任何效果相反,我仍然看到在浏览器中此错误消息(虽然它本身不是也会产生一个错误。)

  [ArgumentException的:不支持关键字:'端口']
   System.Data.Common.DbConnectionOptions.ParseInternal(哈希表parsetable,字符串的connectionString,布尔buildChain,Hashtable的同义词,布尔firstKey)4907604
   System.Data.Common.DbConnectionOptions..ctor(字符串的connectionString,Hashtable的同义词,布尔useOdbcRules)+98
   System.Data.SqlClient.SqlConnectionString..ctor(字符串的connectionString)+55

看起来好像它仍试图使用MS SQL Server驱动程序。

我如何说服它不要?

我使用ASP.NET开发服务器,而不是IIS。起初我以为这rel=\"nofollow\">论坛帖子表明,这可能是问题,但

这个相当精彩 HTTP://www.connectionstrings。 COM / 提供各种连接字符串的例子,和你看起来是确定。很遗憾,您code使用的SqlClient这是在.NET中唯一的SqlServer数据库访问。你将不得不砍了一些code ...

I have an existing ASP.NET app which is configured to connect to a MS SQL Server database and I am trying to modify it to use a postgres database instead.

I would like to avoid modifying the C# code, if possible.

I expected that the following changes would be sufficient:

  1. Add a reference to a suitable postgres driver, in this case NauckIT.PostgreSQLProvider.dll
  2. Add a provider tag to specify the driver to use, in this case:

   <connectionStrings>
     <add name="default" connectionString="Server=127.0.0.1;Port=5432;User Id=finnw;Password=XXX;Database=default;Pooling=false"
       providerName="Npgsql" />

   </connectionStrings>

But the providerName tag seems to have no effect (although it does not in itself generate an error.) Instead I still see this error message in the browser:

[ArgumentException: Keyword not supported: 'port'.]
   System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) +4907604
   System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) +98
   System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) +55

It looks as though it is still trying to use the MS SQL Server driver.

How do I persuade it not to?

I am using ASP.NET Development Server, not IIS. Initially I thought this might be the problem but this forum post suggests otherwise.

解决方案

The rather wonderful http://www.connectionstrings.com/ gives examples of all kinds of connection strings, and yours looks to be OK. Unfortunately your code is using SqlClient which is the SqlServer only database access in .Net. You're going to have to hack some code ...

这篇关于配置ASP.NET开发服务器连接到一个Postgres数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆