C
C#2y ago
Rana

❔ error connection oracle

94 Replies
Kouhai
Kouhai2y ago
conn is null
Rana
RanaOP2y ago
@Kouhai are you here
Kouhai
Kouhai2y ago
Yup!
Rana
RanaOP2y ago
Rana
RanaOP2y ago
this is the connection string why it's return null ?
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionString": {
"OracleConnectionString": "data source=192.168.1.34:1521/orcl;password=RHODES_HR;persist security info=True;user id=RHODES_HR;pooling=true;"
}
}
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionString": {
"OracleConnectionString": "data source=192.168.1.34:1521/orcl;password=RHODES_HR;persist security info=True;user id=RHODES_HR;pooling=true;"
}
}
Kouhai
Kouhai2y ago
Changed ConnectionString to ConnectionStrings
Kouhai
Kouhai2y ago
Rana
RanaOP2y ago
new error
Rana
RanaOP2y ago
The entity type 'USERINFOTEST' requires a primary key to be defined. If you intended to use a keyless entity type, call 'HasNoKey' in 'OnModelCreating'. For more information on keyless entity types, see https://go.microsoft.com/fwlink/?linkid=2141943.
Bing
Under the rainbow
The water pictured crashing down the side of Waime
Rana
RanaOP2y ago
Kouhai
Kouhai2y ago
Can you show your db models?
Rana
RanaOP2y ago
using System.ComponentModel.DataAnnotations;

namespace Nour.DB
{
public class USERINFOTEST
{

[Key]
public string USER_ID { get; set; }

public DateTime TIMESTAMP { get; set; }

public int STATUS { get; set; }

public int PUNCH { get; set; }
}
}
using System.ComponentModel.DataAnnotations;

namespace Nour.DB
{
public class USERINFOTEST
{

[Key]
public string USER_ID { get; set; }

public DateTime TIMESTAMP { get; set; }

public int STATUS { get; set; }

public int PUNCH { get; set; }
}
}
when i put [key] the new error is fetch: Connection string is not well-formed
Rana
RanaOP2y ago
Rana
RanaOP2y ago
this is my connectionsring code
"ConnectionStrings": {
"OracleConnectionString": "data source=192.168.1.34:1521/orcl;password=RHODES_HR;persist security info=True;user id=RHODES_HR;pooling=true;"
}
"ConnectionStrings": {
"OracleConnectionString": "data source=192.168.1.34:1521/orcl;password=RHODES_HR;persist security info=True;user id=RHODES_HR;pooling=true;"
}
How i can fix it ?
Kouhai
Kouhai2y ago
Weird, looks fine to me
Rana
RanaOP2y ago
give you team viwer to see the code ?
Kouhai
Kouhai2y ago
Have you tried connecting to the db using any 3d party tools with same connection string? Sry, can't rn 😄
Rana
RanaOP2y ago
no
Kouhai
Kouhai2y ago
Try DBeaver, free open source sql client
Rana
RanaOP2y ago
my company works in SQL Oracle Developer
Kouhai
Kouhai2y ago
Never used it, don't know how it works 😅 Well, you could also try removing couple of sections from the connection string and re-adding them till the error shows up again
Rana
RanaOP2y ago
this is true in Program.cs ?
Rana
RanaOP2y ago
Kouhai
Kouhai2y ago
Yes, that's correct What happens when you hard code the connection string in Program.cs file, does the same error show up?
Rana
RanaOP2y ago
i dont understand
Kouhai
Kouhai2y ago
Try to replace string conn = builder..... with string conn = "data source=192.168.1.34:1521/orcl;password=RHODES_HR;persist security info=True;user id=RHODES_HR;pooling=true;" Does the error still show up?
Rana
RanaOP2y ago
Kouhai
Kouhai2y ago
Yeah connection string is read correctly No need to replace conn Weird
Rana
RanaOP2y ago
yes the same error
Kouhai
Kouhai2y ago
try to remove the last semicolon here
Rana
RanaOP2y ago
this same the same error *
Kouhai
Kouhai2y ago
monka can't spot anything wrong at all with the connection string tbh
Rana
RanaOP2y ago
~~ it's so bad :/
Kouhai
Kouhai2y ago
Can you try running with a debugger again and checking conn...
Rana
RanaOP2y ago
Kouhai
Kouhai2y ago
Hmmm, try again after removing the trailing semi colon
Rana
RanaOP2y ago
remove ; ? 3 semi colon delete ?
Kouhai
Kouhai2y ago
Yeah, only the last one The one after Pooling=true;
Rana
RanaOP2y ago
i try it but not work
Kouhai
Kouhai2y ago
Yeah, I know, just want to make sure the connection string was read without a ; 😅
Rana
RanaOP2y ago
now work :/
Rana
RanaOP2y ago
Kouhai
Kouhai2y ago
stare you connect to your db using oracle sql developer you mentioned? Also, try to remove the space before "Password" idk if it'll affect it that much
Rana
RanaOP2y ago
Rana
RanaOP2y ago
i can connect to db
Kouhai
Kouhai2y ago
Okay, one last thing, can you send the appsettings.json where the connection string is located in? Send it as an attachment And if you have any confidential info. make sure to delete them before sending here
.aimless.little.moth
You can try to connect using this connection string, I usually connect to oracle using tnsnames.ora file
"OracleConnectionString":"Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=
(PROTOCOL=TCP)(HOST=192.168.1.34)(PORT=1521)))(CONNECT_DATA=orcl)));User Id=RHODES_HR;password=RHODES_HR;"
"OracleConnectionString":"Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=
(PROTOCOL=TCP)(HOST=192.168.1.34)(PORT=1521)))(CONNECT_DATA=orcl)));User Id=RHODES_HR;password=RHODES_HR;"
Rana
RanaOP2y ago
@penera the same error
Rana
RanaOP2y ago
Rana
RanaOP2y ago
Rana
RanaOP2y ago
i will send you the project files
Rana
RanaOP2y ago
Rana
RanaOP2y ago
.aimless.little.moth
Check if this formatting is correct:
"OracleConnectionString": "Data Source=(DESCRIPTION =(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.34)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME=orcl)));User Id=RHODES_HR;password=RHODES_HR;"
"OracleConnectionString": "Data Source=(DESCRIPTION =(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.34)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME=orcl)));User Id=RHODES_HR;password=RHODES_HR;"
Don't have an access to any oracle instance right now to try it out
Rana
RanaOP2y ago
i can access to db the same error
.aimless.little.moth
ok cannot help you then ;/
Kouhai
Kouhai2y ago
@Rana Can you show your db context
Kouhai
Kouhai2y ago
Rana
RanaOP2y ago
using Microsoft.EntityFrameworkCore;

namespace Nour.DB
{
public class DemoDBContext :DbContext
{
public DemoDBContext(DbContextOptions<DemoDBContext> options):base(options) {


}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseOracle("OracleConnectionString");
}

public DbSet<USERINFOTEST> USERINFOTESTs { get; set; }

}
}
using Microsoft.EntityFrameworkCore;

namespace Nour.DB
{
public class DemoDBContext :DbContext
{
public DemoDBContext(DbContextOptions<DemoDBContext> options):base(options) {


}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseOracle("OracleConnectionString");
}

public DbSet<USERINFOTEST> USERINFOTESTs { get; set; }

}
}
Kouhai
Kouhai2y ago
Voila!
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseOracle("OracleConnectionString");
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseOracle("OracleConnectionString");
}
Rana
RanaOP2y ago
delete it ?
Kouhai
Kouhai2y ago
Yeah, just delete it, you don't need to override in your case
Rana
RanaOP2y ago
new error
Kouhai
Kouhai2y ago
Basically you were connecting using "OracleConnectionString" not the actual connection string
Rana
RanaOP2y ago
Rana
RanaOP2y ago
Kouhai
Kouhai2y ago
Try testing the connection in database developer, does it timeout?
Rana
RanaOP2y ago
it's connect
Kouhai
Kouhai2y ago
Okay Try to increase the timeout in your connection stirng
Rana
RanaOP2y ago
how ?
Kouhai
Kouhai2y ago
add Connection Timeout=200 In the connection string
Rana
RanaOP2y ago
"OracleConnectionString": "data source=192.168.1.34:1521/orcl;password=RHODES_HR;Connection Timeout=200;persist security info=True;user id=RHODES_HR;pooling=true"
"OracleConnectionString": "data source=192.168.1.34:1521/orcl;password=RHODES_HR;Connection Timeout=200;persist security info=True;user id=RHODES_HR;pooling=true"
like this ?
Kouhai
Kouhai2y ago
Yup!
Rana
RanaOP2y ago
the same
Kouhai
Kouhai2y ago
Can you show the GetData endpoint?
Rana
RanaOP2y ago
Kouhai
Kouhai2y ago
I'm not entirely sure what can cause timeout with an oracle db, but can you check current connections in sql developer?
Rana
RanaOP2y ago
yes it's connect to db
Kouhai
Kouhai2y ago
No I mean like Can you check how many connections currently exist?
Rana
RanaOP2y ago
45
Rana
RanaOP2y ago
Kouhai
Kouhai2y ago
45 with the ASP app running?
Rana
RanaOP2y ago
when i run the asp it's 41
Kouhai
Kouhai2y ago
And when you close it?
Rana
RanaOP2y ago
45 now 41
Kouhai
Kouhai2y ago
And when you try to access GetData ?
Rana
RanaOP2y ago
48
Kouhai
Kouhai2y ago
So when the request is made it's always over 45
Rana
RanaOP2y ago
Connection request timed out the appsettings is correct ?
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"OracleConnectionString": "data source=192.168.1.34:1521/orcl;password=RHODES_HR;persist security info=True;Connection Timeout=200;User d=RHODES_HR;pooling=true;"
}


}
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"OracleConnectionString": "data source=192.168.1.34:1521/orcl;password=RHODES_HR;persist security info=True;Connection Timeout=200;User d=RHODES_HR;pooling=true;"
}


}
and this is the Program.cs
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using Oracle.EntityFrameworkCore;
using Oracle.ManagedDataAccess;
using Nour.DB;
using Oracle.ManagedDataAccess.Client;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();

var conn = builder.Configuration.GetConnectionString("OracleConnectionString");
builder.Services.AddDbContext<DemoDBContext>(options=> options.UseOracle(conn));



// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using Oracle.EntityFrameworkCore;
using Oracle.ManagedDataAccess;
using Nour.DB;
using Oracle.ManagedDataAccess.Client;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();

var conn = builder.Configuration.GetConnectionString("OracleConnectionString");
builder.Services.AddDbContext<DemoDBContext>(options=> options.UseOracle(conn));



// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
it's ture?
Kouhai
Kouhai2y ago
This is wrong
Rana
RanaOP2y ago
the same i try 10000 connection strings
Kouhai
Kouhai2y ago
can you try to remove pooling?
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server