So I've got a database target to write logs to an Oracle database table but I cannot seem to get it to write to the table. I've tried various dbProviders and usually get an error like below
<target name="database" xsi:type="Database" connectionString="${var:ConnectionStrings}" dbProvider="Oracle.ManagedDataAccess.Client.OracleConnection, Oracle.ManagedDataAccess"
commandType="Text" keepConnection="false"
commandText="INSERT INTO SAMS.LOG (ID, LOGLEVEL, MESSAGE, LOGGER, CALLSITE, EXCEPTIONDETAIL, USERNAME, IPADDRESS)
VALUES('',
:LogLevel,
:Message,
:Logger,
:Callsite,
:ExceptionType,
:UserName,
:IpAddress);" >
<parameter name="Logged" layout="${date}" />
<parameter name="LogLevel" layout="${level}" />
<parameter name="Message" layout="url: ${aspnet-request-url} | action: ${aspnet-mvc-action} | ${message}" />
<parameter name="Logger" layout="${logger}" />
<parameter name="Callsite" layout="${callsite:filename=true}" />
<parameter name="ExceptionType" layout="${exception:tostring}" />
<parameter name="UserName" layout="${aspnet-user-identity}" />
<parameter name="IpAddress" layout=" ${aspnet-request-ip}" />
</target>
This is the furthest I've been able to get to in the process. It has attempted to write to the database but something is off in my connection string.
2018-10-23 14:13:28.1934 Error DatabaseTarget(Name=database_wrapped): Error when writing to database. Exception: Oracle.ManagedDataAccess.Client.OracleException (0x80004005): ORA-12514: TNS:listener does not currently know of service requested in connect descriptor ---> OracleInternal.Network.NetworkException (0x000030E2): ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
at OracleInternal.Network.OracleCommunication.DoConnect(String tnsDescriptor)
at OracleInternal.ServiceObjects.OracleConnectionImpl.Connect(ConnectionString cs, Boolean bOpenEndUserSession, OracleConnection connRefForCriteria, String instanceName)
at OracleInternal.ConnectionPool.PoolManager`3.Get(ConnectionString csWithDiffOrNewPwd, Boolean bGetForApp, OracleConnection connRefForCriteria, String affinityInstanceName, Boolean bForceMatch)
at OracleInternal.ConnectionPool.OraclePoolManager.Get(ConnectionString csWithNewPassword, Boolean bGetForApp, OracleConnection connRefForCriteria, String affinityInstanceName, Boolean bForceMatch)
at OracleInternal.ConnectionPool.OracleConnectionDispenser`3.Get(ConnectionString cs, PM conPM, ConnectionString pmCS, SecureString securedPassword, SecureString securedProxyPassword, OracleConnection connRefForCriteria)
at Oracle.ManagedDataAccess.Client.OracleConnection.Open()
at NLog.Targets.DatabaseTarget.OpenConnection(String connectionString)
at NLog.Targets.DatabaseTarget.EnsureConnectionOpen(String connectionString)
at NLog.Targets.DatabaseTarget.WriteEventToDatabase(LogEventInfo logEvent)
at NLog.Targets.DatabaseTarget.Write(IList`1 logEvents)
My appsettings.json contains the connection string
"ConnectionStrings": {
"NLogDb": "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)
(HOST=fleetqadb.xxx.com)(PORT=1521))(CONNECT_DATA=
(SERVICE_NAME=orcl.fleetqadb.xxx.com)));User
Id=samsuser;Password=xxxxx;",
}
If anyone has any ideas, I'd greatly appreciate it!
I don't know NLog, but ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
means that the database you want to insert data to is unknown.
If it was pure Oracle, I'd say that database's alias doesn't exist in the TNSNAMES.ORA
In your case, you provided "ConnectionString"
(mind you: at the beginning of your message, you call it a connectionString
, while at the end of the message you call it ConnectionStrings
- note the trailing s
, as well as letter case. I don't know which one (or both?) of those matters).
"Data source" is the database you're trying to connect to. Apparently, what you wrote in there is invalid.
I have the TNSNAMES.ORA and can tnsping
my database as
C:\>tnsping xe
TNS Ping Utility for 64-bit Windows: Version 11.2.0.2.0 - Production on 23-LIS-2018 21:07:09
Copyright (c) 1997, 2014, Oracle. All rights reserved.
Used parameter files:
C:\Users\lf\Documents\E_0_library\sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = lflp.dt.center)(
PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)))
OK (10 msec)
I'm not a DBA, but - check your host
and service_name
values.
My suggestion: as a service_name
, put orcl
only (instead of orcl.fleetqadb.xxx.com
) and see what happens.
User contributions licensed under CC BY-SA 3.0