Hi everyone,
I'm trying to connect to an Oracle database from a .NET application using the Oracle.EntityFrameworkCore NuGet package, but I keep encountering authentication errors. Interestingly, I can connect successfully using DBeaver with the same credentials.
I've already tried several possible solutions but haven't been able to resolve the issue.
Things I have tested:
- Tried different versions of the package.
- Checked the connection string and tested various formats (included in my code).
- Verified that the correct values are being used when creating the connection.
- My username and password do not contain special characters. Only underscores, which should not be problematic.
- Checked for any invisible characters being sent with the credentials.
- Confirmed that the host is accessible. I do need to use a VPN, but the server is being reached correctly.
I was encountering the problem in my main project, so I created a new simple console project to test it separately, in case there were any incompatibilities with other packages.
Code:
using Oracle.ManagedDataAccess.Client;
var connectionString1 = "User Id={user};Password={password};Data Source={host}:1521/{db}";
var connectionString2 = "User Id={user};Password={password};Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST={host})(PORT=1521))(CONNECT_DATA=(SID={db})))";
var connectionString3 = "User Id={user};Password={password};Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST={host})(PORT=1521))(CONNECT_DATA=(SERVICE_NAME={db})))";
var builder = new OracleConnectionStringBuilder(connectionString1);
Console.WriteLine($"User ID: {builder.UserID}");
Console.WriteLine(string.Join(",", builder.UserID.Select(c => ((int)c).ToString())));
Console.WriteLine($"Password: {builder.Password}");
Console.WriteLine(string.Join(",", builder.Password.Select(c => ((int)c).ToString())));
Console.WriteLine($"Data Source: {builder.DataSource}");
Console.WriteLine($"Connection String: {builder.ConnectionString}");
try
{
using var connection = new OracleConnection(connectionString1);
connection.Open();
connection.Close();
}
catch (Exception ex)
{
Console.WriteLine("Connection failed: " + ex.Message);
}
Error:
Connection failed: ORA-01017: invalid username/password; logon denied https://docs.oracle.com/error-help/db/ora-01017/
Environment:
- Oracle.EntityFrameworkCore: 9.23.80 (also tested with lower versions, the error persists)
- .NET 8.0
- IDE: Visual Studio 2022
Any ideas or suggestions would be greatly appreciated. Thanks!
Edit:
The database isn’t mine, but I was able to figure out its version. It appears to be Oracle9i Enterprise Edition Release 9.2.0.7.0 - 64-bit Production, which was released sometime between 2002 and 2007.
This might be a silly question, but does anyone know if there could be compatibility issues because of this?