标签: npgsql

PostgreSQL SSPI身份验证 - 致命:2801:用户"xxx"的密码身份验证失败

我对PostgreSQL很陌生,对MS SQL Server有相当多的经验.引起我注意的PostgreSQL的一个特性是SSPI身份验证,我希望这样可以更轻松地从MS SQL过渡.但是,我似乎无法让它发挥作用.

目前,服务器和客户端都在同一台Windows 7上运行,该机器不是域的成员.如果我理解正确,SSPI auth从Kerberos回退到NTLM,所以它应该在没有域的情况下工作 - 我是对的吗?

当我尝试连接(从.NET应用程序通过Npgsql)时,我得到一条NpgsqlException消息:Fatal: 28P01: password authentication failed for user "xxx"消息对我来说有点令人费解,因为我没有使用密码验证.

我的pg_hba.conf:

host    all             all             127.0.0.1/32            md5
host    all             all             ::1/128                 md5
host    all             all             127.0.0.1/32            sspi
Run Code Online (Sandbox Code Playgroud)

Npgsql连接字符串:

Server=127.0.0.1;Port=5432;Database=mydb;Integrated Security=true;

我在这做错了什么?或者是没有域名它不起作用?

sql authentication postgresql npgsql

6
推荐指数
1
解决办法
3987
查看次数

在Npgsql中是否有任何SQLBulkCopy的等价物

经过一番搜索后,我找不到在Npgsql中从SQLClient中正确替换SQLBulkCopy.任何人都可以建议我像PostBSQL的SQLBulkCopy吗?我需要插入大约1000万个数据..我知道单个查询插入...

我只是为了比较而做测试.

任何建议表示赞赏.

c# sql-server postgresql npgsql

6
推荐指数
1
解决办法
2101
查看次数

使用ADO.NET进行PostgreSQL参数化插入

我正在使用NpgSQL与PostgreSQL和ADO.NET.原谅这个问题的简单性,因为我本周刚刚开始使用PostgreSQL和NpgSQL.

这样的事情很好:

[Test]
public void InsertNoParameters()
{
    NpgsqlConnection conn = new NpgsqlConnection("Host=localhost; Database=postgres; User ID=postgres; Password=password");
    conn.Open();

    IDbCommand command = conn.CreateCommand();
    string sql = "INSERT INTO Customers (FirstName,LastName) VALUES ('Test','Tube')";
    command.CommandText = sql;
    command.ExecuteNonQuery();
    conn.Close();
}
Run Code Online (Sandbox Code Playgroud)

当我输入参数时,我收到错误消息:Npgsql.NpgsqlException:错误:42703:列"_firstname"不存在

[Test]
public void InsertWithParameters()
{
NpgsqlConnection conn = new NpgsqlConnection("Host=localhost; Database=postgres; User ID=postgres; Password=password");
conn.Open();

IDbCommand command = conn.CreateCommand();
string sql = "INSERT INTO Customers (FirstName,LastName) VALUES (_FirstName,_LastName)";
command.CommandText = sql;

var parameter = command.CreateParameter();
parameter.ParameterName = "_FirstName";
parameter.Value = "Test";
command.Parameters.Add(parameter);

parameter …
Run Code Online (Sandbox Code Playgroud)

postgresql npgsql

6
推荐指数
1
解决办法
7203
查看次数

Npgsql提供程序是否支持TransactionScope?

我正在尝试与Npgsql提供程序一起使用TransactionScope。我在一个古老的问题(.net中的PostgreSQL提供程序,支持TransactionScope)中发现Npgsql还不支持它。现在,大约5年后,Npgsql是否支持TransactionScope?我使用Npgsql 3.0.3并使用以下代码对自己进行了测试:

using (var scope = new TransactionScope())
{
    using(var connection = new Npgsql.NpgsqlConnection("server=localhost;user id=*****;password=*****database=test;CommandTimeout=0"))
    {
        connection.Open();

        var command = new NpgsqlCommand(@"insert into test.table1 values ('{10,20,30}', 2);");
        command.Connection = connection;
        var result = command.ExecuteNonQuery();

        // scope.Complete();  <-- Not committed
    }
}
Run Code Online (Sandbox Code Playgroud)

任何人都可以确认Npgsql不支持TransactionScope吗?

编辑#1 确认Npgsql对TransactionScope的支持后,我发现您需要确保在PostgreSQL配置中启用了分布式事务,请检查postgres.conf文件中的max_prepared_transactions参数(记住要重新启动服务器) 。

编辑#2 我在服务器上启用了分布式事务,但是现在在使用TransactionScope和Npgsql时出现错误。这是我的代码:

using (var sourceDbConnection = new NpgsqlConnection(SourceConnectionString))
using (var destinationDbConnection = new NpgsqlConnection(DestinationConnectionString))
using (var scope = new TransactionScope())
    {
        sourceDbConnection.Open();
        destinationDbConnection.Open();

        Logger.Info("Moving data for the {0} table.", …
Run Code Online (Sandbox Code Playgroud)

npgsql

6
推荐指数
1
解决办法
4031
查看次数

在PowerBI中安装ngpsql以使用PostgreSQL

我正在尝试将数据从PostgreSQL数据库获取到PowerBI Desktop,但它似乎不起作用。我认为问题在于使用npgsql进行安装。当尝试在PowerBI中设置新的数据库连接时,我输入数据库和服务器,这是我得到的错误消息:

“无法连接详细信息:” PostgreSQL:我们找不到具有不变名称'Npgsql'的数据库提供程序。可能是由于需要特定于提供程序的客户端软件而导致的,但此计算机上没有此错误。要下载此提供程序的客户端软件,请访问以下网站,并至少选择64位(x64)版本的“ Npgsql版本2.0.12”:https ://go.microsoft.com/fwlink/?LinkID = 282716 “”

我试过去npgsql网站并安装所需的组件,但似乎无法正常工作。我不是开发人员,所以这对我来说有点复杂。有谁知道如何安装这些组件?非常感谢您的帮助!

如果有帮助,我将在Surface Pro 3上使用Windows 10。而且我也安装了Visual Studio Community。

最好,布鲁诺。

npgsql

6
推荐指数
2
解决办法
6987
查看次数

Asp.Net核心如何更换配置管理器

我是ASP.NET Core RC2的新手,我想知道如何获得一些配置设置并将其应用到我的方法中.对于我的实例appsettings.json我有这个特定的设置

"ConnectionStrings": {
    "DefaultConnection": 
        "Server=localhost;User Id=postgres;port=5432;Password=castro666;Database=dbname;"
  }
Run Code Online (Sandbox Code Playgroud)

在我的Controller中,每次我想查询数据库时,我都必须使用此设置

 using (var conn = 
     new NpgsqlConnection(
         "Server=localhost;User Id=postgres;port=5432;Password=castro666;Database=dbname;"))
 {
     conn.Open();
 }
Run Code Online (Sandbox Code Playgroud)

这里显而易见的是,如果我想在配置中添加更多内容,我必须更改该方法的每个实例.我的问题是如何才能进入DefaultConnection,appsettings.json这样我才能做到这一点

 using (var conn = 
     new NpgsqlConnection(
         ConfigurationManager["DefaultConnection"))
 {
     conn.Open();
 }
Run Code Online (Sandbox Code Playgroud)

c# asp.net npgsql asp.net-core asp.net-core-1.0

6
推荐指数
2
解决办法
9124
查看次数

通过在 JSONB 列上应用过滤器来查询 postgresql 中的数据

我有一个有 2 列的表;ID (int) and EntityData (JSON)。我在 C# 中以字典的形式创建了一个过滤器对象。我想获取满足过滤器中键值对数据的所有行。

示例过滤器是:

{
    "Name": "mike",
    "Location": "Lagos"
}
Run Code Online (Sandbox Code Playgroud)

这应该获取 EntityData 名称为 mike、位置为 Lagos 的所有行。

postgresql npgsql cockroachdb

6
推荐指数
1
解决办法
2万
查看次数

PostgreSQL 设置会话变量

我的应用程序使用相同的凭据连接到 PostgreSQL 数据库(数据库提供商要求...)但是我需要识别哪个应用程序用户正在连接到数据库(例如用于更新审核等)

我想知道是否有任何方法可以设置一些变量(其生命仅限于会话),然后我可以通过 DDL 读取该变量。

** 编辑 **

我还做了一些实验,在连接字符串中使用 application_name 并放置简单的用户登录 - 但这不是最优雅的方式......

SET application_name TO 'user_login';
select current_setting('application_name');
Run Code Online (Sandbox Code Playgroud)

知道如何存档吗?

.net postgresql auditing npgsql

6
推荐指数
1
解决办法
2万
查看次数

是否可以使用 npgsql 在 EF CORE 3.1 中使用 UNACCENT 扩展对 postgresql 进行选择?

我已经在 Npgsql and Entity Framework Query PostgreSQL with Npgsql and Entity Framework using unaccent中读到过有关此内容,但实体框架核心。

\n\n

是否可以使用 EF CORE 3.1 使用非重音扩展对 postgresql 进行选择?

\n\n

如何翻译,例如

\n\n
\n

select * from users where unaccent(name) = unaccent(\'Jo\xc3\xa3o\')

\n
\n\n

使用 EF core 和 npgsql 到 .net core 3.1

\n\n

谢谢

\n

postgresql npgsql ef-core-3.1

6
推荐指数
1
解决办法
455
查看次数

Postegres ef-core 更新数据库产生“42P01:关系“__EFMigrationsHistory”不存在”错误

设置

Asp.NET core网站2.2和EF Core 2.2
具有多个模式的Postgresql数据库,并且其中一个模式已经有__EFMigrationsHistory


当尝试时

Add-Migration x1 -Context YodaContext 有用

但是当第一次尝试以下语句时
Update-Database -Context YodaContext(我在此架构中没有任何表,这是第一个更新数据库),我看到以下错误。

Failed executing DbCommand (85ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT "MigrationId", "ProductVersion"
FROM "__EFMigrationsHistory"
ORDER BY "MigrationId";
Npgsql.PostgresException (0x80004005): 42P01: relation "__EFMigrationsHistory" does not exist
   at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<<ReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<<ReadMessage>g__ReadMessageLong|0>d.MoveNext() in C:\projects\npgsql\src\Npgsql\NpgsqlConnector.cs:line 1032
--- End of stack trace from previous location where exception was thrown ---
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming) …
Run Code Online (Sandbox Code Playgroud)

postgresql npgsql entity-framework-migrations ef-core-2.2

6
推荐指数
2
解决办法
8929
查看次数