Using SSPI to connect to remote PostgreSQL server using Npgsql - postgresql

I am using nHibernate + Npgsql to connect to PostgreSQL server using windows authentication (SSPI). I have added the windows user to the Postgres and have configured the settings as recommended by http://wiki.postgresql.org/wiki/Configuring_for_single_sign-on_using_SSPI_on_Windows.
Here is my connection string:
"Server=;Port=5432;Database=;Integrated Security=true"
This is my code:
if (!sessionFactories.TryGetValue(sessionFactoryConfigPath, out sessionFactory))
{
Configuration cfg = new Configuration();
if (sessionFactoryConfigPath != DefaultConfigFile)
{
//Check.Require(File.Exists(sessionFactoryConfigPath),
// "The config file at '" + sessionFactoryConfigPath + "' could not be found");
cfg.Configure(sessionFactoryConfigPath);
}
else
{
cfg.Configure();
}
// Now that we have our Configuration object, create a new SessionFactory
sessionFactory = cfg.BuildSessionFactory();
When I run this I get the following error at sessionFactory = cfg.BuildSessionFactory();
"FATAL: XX000: could not accept SSPI security context"
When I checked the PostgreSQL logs the following entry was found:
"The token supplied to the function is invalid (80090308)"
I am using "PostgreSQL 9.3.2, compiled by Visual C++ build 1600, 32-bit". I got it from postgres website. I am using Windows 7 SP1 64-bit.
What am I missing here? Please help.

Related

Oracle SQL Loader client unable to connect to server on LAN

I had a long running bash script/MySQL code to LOAD FILE into MySQL database.
I needed to convert this to Windows environment and Oracle DB. Wrote a PowerShell program and one of the lines in code uses sql loader to load files into oracle DB. The DB is in another system in LAN and I am connecting from a windows server system where I have installed the oracle full client (not just instant client) package.
Before using SQL Loader, I made sure that I am able to connect to DB from the system. The following SQL plus command works
Before using SQL Loader, I made sure that I am able to connect to DB from the system.
The following SQL plus command works
sqlplus abc/oracleabc#'"(description=(address=(host=192.168.22.44)(protocol=tcp)(port=1521))(connect_data=(sid=orcl)))"'
However I am not able to make SQL Loader work in PowerShell script.
I tried multiple command formats and connection strings
Try-1 :
sqlldr.exe abc/oracleabc#'"(description=(address=(host=192.168.22.44)(protocol=tcp)(port=1521))(connect_data=(sid=orcl)))"' control=$ctl_file_name direct='true'
Result :
LRM-00116: syntax error at 'address' following '('
Try-2:
sqlldr.exe 'abc/oracleabc#(description=(address=(host=192.168.22.44)(protocol=tcp)(port=1521))(connect_data=(sid=orcl)))' control=$ctl_file_name
Result :
LRM-00116: syntax error at 'address' following '('
Try-3
sqlldr.exe abc/oracleabc#"(DESCRIPTION\=(ADDRESS_LIST\=(ADDRESS\=(PROTOCOL\=TCP)(HOST\=192.168.22.44)(Port\=1521)))(CONNECT_DATA\=(SERVICE_NAME\=orcl)))" control=$ctl_file_name
Result:
SQL*Loader-704: Internal error: ulconnect:
OCIServerAttach [0]
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
Try-4
sqlldr.exe userid=abc/oracleabc#ORCL control=$ctl_file_name
Result:
SQL*Loader-704: Internal error: ulconnect:
OCIServerAttach [0]
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
Environmental variable ORACLE_HOME is defined in the system and points to client installation director D:\app\client\abc\product\19.0.0\client_1
tnanames.ora File :
# tnsnames.ora Network Configuration File:
D:\app\client\abc\product\19.0.0\client_1\NETWORK\ADMIN\tnsnames.ora
# Generated by Oracle configuration tools.
ORCL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.22.44)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
sqlnet.ora File
# sqlnet.ora Network Configuration File:
D:\app\client\abc\product\19.0.0\client_1\NETWORK\ADMIN\sqlnet.ora
# Generated by Oracle configuration tools.
# This file is actually generated by netca. But if customers choose to
# install "Software Only", this file wont exist and without the native
# authentication, they will not be able to connect to the database on NT.
SQLNET.AUTHENTICATION_SERVICES= (NTS)
NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)
TNS Ping:
C:\Users\abc>tnsping orcL
TNS Ping Utility for 64-bit Windows: Version 19.0.0.0.0 - Production on 04-MAY-2022
08:14:07
Used parameter files:
D:\app\client\abc\product\19.0.0\client_1\network\admin\sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST =
192.168.22.44)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = orcl)))
OK (20 msec)
Need help in identifying the connection parameter/format issue related to SQL Loader.

Deleted the DB2 Service Credentials. Created new credentials. New username and password not recognized for connection

#I'm using IBM DB2 on the cloud service (lite) of IBM. I deleted the DB2 Service Credentials but I didn't get to save the original password and username. I deleted that credential and created a new one. But using the ibm_db commands from python notebooks and sql to connect to the database, an error occurs:
SQLCODE=-30082ct: [IBM][CLI Driver] SQL30082N Security processing failed with reason "24" ("USERNAME AND/OR PASSWORD INVALID"). SQLSTATE=08001
I've tried repeatedly deleting and creating new service credentials but same error occurs. Not sure if I need the original or something. Is there a way to implement the password change without access to the original?
I use the following python code using a jupyter notebook. I assign the dsn_driver and others as a string e.g. dsn_uid = "abc1234".
import ibm_db
dsn = (
"DRIVER={0};"
"DATABASE={1};"
"HOSTNAME={2};"
"PORT={3};"
"PROTOCOL={4};"
"UID={5};"
"PWD={6};"
"SECURITY={7};").format(dsn_driver, dsn_database, dsn_hostname, dsn_port, dsn_protocol, dsn_uid, dsn_pwd,dsn_security)
try:
conn = ibm_db.connect(dsn, "", "")
print ("Connected to database: ", dsn_database, "as user: ", dsn_uid, "on host: ", dsn_hostname)
except:
print ("Unable to connect: ", ibm_db.conn_errormsg() )
RESULTS:

Neo-4j ETL Tool won't connect to local postgres Server. org.postgresql.util.PSQLException: The authentication type 10 is not supported

I am using Neo4j version 1.4.1 and PostgresSQL 13 with PgAdmin 4.30. I recently installed PostgreSQL 13, before that I had PostgreSQL 12 and PgAdmin 4.24 when this ETL import thing worked.
But now, after removing PostgreSQL 12, I was trying to import my local postgres database to Neo-4j using the neo4j ETL tool.
My input connection detail:
Host= localhost
Port= 5432
Database= mydatabasename
Connection URL= jdbc:postgresql://localhost:5432/mydatabasename
Username=myUsername password="mypassword"
But when I click the Test and Save Connection button, it shows this error:
Jan 30, 2021 1:10:43 AM org.postgresql.Driver connect SEVERE:
Connection error: org.postgresql.util.PSQLException: The
authentication type 10 is not supported. Check that you have
configured the pg_hba.conf file to include the client's IP address or
subnet, and that it is using an authentication scheme supported by the
driver. at
org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:614)
at
org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:222)
at
org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.(PgConnection.java:194) at
org.postgresql.Driver.makeConnection(Driver.java:431) at
org.postgresql.Driver.connect(Driver.java:247) at
java.sql.DriverManager.getConnection(DriverManager.java:664) at
java.sql.DriverManager.getConnection(DriverManager.java:247) at
org.neo4j.etl.rdbms.Support.testConnection(Support.java:32) at
org.neo4j.etl.rdbms.Support.main(Support.java:74)
Connection failed. SQL state: 08004, message: The authentication type
10 is not supported. Check that you have configured the pg_hba.conf
file to include the client's IP address or subnet, and that it is
using an authentication scheme supported by the driver.
I took the help of this post Unable to connect to Postgress DB due to the authentication type 10 is not supported. I tried changing my pg_hba.conf settings and set the method to md5:
local all all md5
I also configured my postgresql.conf like this:
listen_addresses = '*' port = 5432 max_connections = 100 password_encryption = md5
But nothing worked. I even tried reinstalling PostgreSQL 13 and PgAdmin 4.30.
I downloaded the latest JDBC version and tried to connect using that postgresql-42.2.18.jre7, but the same error. When I'm using a Java program to connect to this database, the connection is successful.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JavaPostgresIntegration {
public static void main(String[] args) {
Connection c = null;
try {
Class.forName("org.postgresql.Driver");
c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/mydatabase", "postgres", "mypassword");
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getClass().getName() + ": " + e.getMessage());
System.exit(0);
}
System.out.println("Opened database successfully");
try {
c.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Output: Opened database Successfuly
(I am using the downloaded postgresql-42.2.18.jre7 for this program.)
Edit: I installed PostgreSQL 12 and it solved the problem. While when I was connecting to PostgreSQL 13 using Neo4j the error was still there.

Crystal Reports: Error connecting to SQL server

On our machine (Windows Server 2012R2), we have an ASP.net website that uses Crystal Reports (2008) for some reports. The database is SQL Server 2014. Here is the code related to the error:
ConnectionInfo cnnInfo = new ConnectionInfo();
cnnInfo.ServerName = serverName;
cnnInfo.DatabaseName = dbName;
cnnInfo.UserID = userId;
cnnInfo.Password = password;
ReportDocument rd = new ReportDocument();
rd.Load(rptUrl);
RptViewer.ReportSource = rd;
CrystalDecisions.CrystalReports.Engine.Database rptDb = rd.Database;
TableLogOnInfo tblLogOnInfo = new TableLogOnInfo();
foreach (CrystalDecisions.CrystalReports.Engine.Table tbl in rptDb.Tables)
{
tblLogOnInfo = tbl.LogOnInfo;
tblLogOnInfo.ConnectionInfo = cnnInfo;
tbl.ApplyLogOnInfo(tblLogOnInfo);
tbl.Location = tbl.Location.Substring(tbl.Location.LastIndexOf(".") + 1);
}
Here is the error that happens at this line:
tbl.Location = tbl.Location.Substring(tbl.Location.LastIndexOf(".") + 1);
Logon failed.
Details: ADO Error Code: 0x
Source: Microsoft OLE DB Provider for SQL Server
Description: [DBNETLIB][ConnectionOpen (SECCreateCredentials()).]SSL Security error.
SQL State: 08001
Native Error: Error in File C:\Windows\TEMP\EventByEventTypeCrossTab {FC74CD56-B1FF-4B06-9566-B927D660617D}.rpt:
Unable to connect: incorrect log on parameters.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: Logon failed.
Details: ADO Error Code: 0x
Source: Microsoft OLE DB Provider for SQL Server
Description: [DBNETLIB][ConnectionOpen (SECCreateCredentials()).]SSL Security error.
SQL State: 08001
Native Error: Error in File C:\Windows\TEMP\EventByEventTypeCrossTab {FC74CD56-B1FF-4B06-9566-B927D660617D}.rpt:
Unable to connect: incorrect log on parameters.
Note that the same database account is used to read the database and display info in the browser without any problem.
How can I fix it?
I got it working finally. Here is what I did:
Upgrade to .NET framework 4.7.2
Install CR for .NET framework 4
Followed the solution in this link:
https://community.ipswitch.com/s/article/How-to-resolve-SSL-Security-error-and-SECCreateCredentials-failures-in-Admin-Console-and-ODBC-connections-after-disabling-SSL-and-TLS1-0-protocols-on-the-WhatsUp-Gold-server
Restart the server.

The user instance login flag is not supported on this version of SQL Server. The connection will be closed, error login

I have Windows 7, Microsoft SQL Server 2008 R2 and Visual Studio 2010.
First question: I don't change my password in sql, although my security its setting follow:
server authentication: sql server windows authentication mode
login auditing: Failed logins only
and for user sa or any users:
permission: Grant
Login: Enabled
but, my any password will 32 numbers.
Second question:
Then, I never can connect to database in Visual Studio, such as Entity Framework way, with uid and with Integrated Security=True;User Instance=True;
So, when I ctrl+f5 in VS, and I expect true working my app and ajax, I instead get error.
My code:
function FillGrid() {
$.ajax({
url: "ajax_process.aspx?cmd=FillGrid",
type: "POST",
data: null,
async: true,
success: function (dataFromServer) {
d = eval("(" + dataFromServer + ")");
alert(d[0].email);
},
error: function (XMLResponse) {
alert(XMLResponse.responseText);
}
});
}
My error is alert:
The user instance login flag is not supported on this version of SQL Server. The connection will be closed.
and:
SqlException (0x80131904): The user instance login flag is not supported on this version of SQL Server. The connection will be closed.]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +6352224
User Instances are a Sql Server Express only feature.
This is how to do fix this in VS 2010:
In VS2010 IDE, right-click on your database > Modify Connection > Advanced > Source.
In source change User Instance to false then in Sql Explorer panel refresh to see your database contents - that's all that's needed.
Note: some times you need to delete User Instance = true; in your connection string (that for example you use in your data access class).
Add new ADO.net entity data model
In the wizard: select 'EF designer from database'
Select new connection button
Change data source from 'microsoft sql server' to 'microsoft sql server database file'
Browse your database.