I use a vb application that connect to an Oracle service by an Oracle client 10g:
Protected cnS3 As OracleConnection
cnS3 = New OracleConnection(String.Format("Data Source={0};user id={1}; password={2}; ", _
"myDataSource10", "dbUser", "dbUserPassword"))
But the db provider has dismissed the Oracle user and has provided me a proxy user. It told me to connect with the proxy user and Oracle client 11.2.0.4.
So I've installed the Oracle client 11g and created a new ODBC DSN "myDataSource11" with Oracle 11g version (tested and worked in the ODBC Data Sources Interface).
But when replace the code as follows:
Protected cnS3 As OracleConnection
cnS3 = New OracleConnection(String.Format("Data Source={0};user id={1}; password={2}; ", _
"myDataSource11", "dbProxyUser[dbUser]", "dbProxyUserPassword"))
I have the error: [OracleException (0x80131938): ORA-12154: TNS:could not resolve the connect identifier specified
I have also tried with this code:
oradb = "Data Source=(DESCRIPTION = (ADDRESS_LIST = (LOAD_BALANCE = ON) (FAILOVER = ON)" _
+ "(ADDRESS=(PROTOCOL=tcp)(HOST=myhostname)(PORT=5555))" _
+ "(ADDRESS=(PROTOCOL=tcp)(HOST=myhostname2)(PORT=5555)))(CONNECT_DATA" _
+ "= (SERVICE_NAME = myServiceName )));" _
+ "User Id=dbProxyUser[dbUser];Password=dbProxyUserPassword;"
cnS3 = New OracleConnection(oradb)
And in this case the error is [ArgumentException: Lunghezza dell'opzione di connessione "user id" non valida. La lunghezza massima รจ 30.]
I've resolved replacing the OracleConnection with OdbcConnection.
The proxy user has been added also in the web.config and the password of the proxy user has been added in the odbc, as explained at https://community.oracle.com/tech/developers/discussion/2209660/ora-01005-null-password-given-error-on-windows-7
Related
ALL,
Does GRANT-ing permissions supported in MS ACCESS?
I am connecting to accdb with ODBC driver from C++ app and trying to issue a GRANT command, but getting an error saying expecting DELETE, INSERT, PROCEDURE, SELECT or UPDATE.
It is on Windows 8.1 with MSVC 2017 Community.
The command I'm trying is:
GRANT SELECT ON MSysObjects TO Admin;
TIA!!
void uc_to_str_cpy(SQLWCHAR *dest, const std::wstring &src)
{
const wchar_t *temp = src.c_str();
while( *dest )
{
dest++;
}
while( *temp )
{
*dest = *temp;
dest++;
temp++;
}
*dest++ = 0;
*dest = 0;
}
std::wstring query8 = L"GRANT SELECT ON MSysObjects TO Admin;";
query = new SQLWCHAR[query8.length() + 2];
memset( query, '\0', query8.length() + 2 );
uc_to_str_cpy( query, query8 );
ret = SQLExecDirect( m_hstmt, query, SQL_NTS );
delete[] query;
query = NULL;
if( ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO )
{
GetErrorMessage( errorMsg, 1 );
result = 1;
}
Grant does exist for Access. In most cases you can query against MSYSobjects. However, you could try several things:
First, try running your program (.exe) with elevated rights (right click and run as admin).
next up. You don't mention if this is JET (mdb) format, or is ACE (accdb format).
HOWEVER - using ODBC (as opposed to the oleDB driver), to my knowledge DOES NOT support Grant. So, quite sure you are out of luck.
You could I suppose consider creating a ADO object.
I find that EVEN inside of Access, if I use the built in ADO object, then grant will work.
but if I use a straight DAO object, then it does not work.
and for ODBC? Well, I find that grant does not seem to be supported - so, this looks like ODBC does NOT support the grant.
Also, use of GRANT in most cases also means that the connection string needs to include the work group file (it is by default automatic opened - even with ODBC, but using oleDB against such a database (from .net), I again find that GRANT does execute with oleDB - but gives an error message about the workgroup file having not been specified.
However, with ODBC - I get a error - syntax. So, at this point? ODBC does not support the grant DDL.
I'm trying to connect to an Oracle 19 database using unixODBC 2.3.7.
I'm using the Oracle Developer Days VirtualBox VM.
When trying to troubleshoot via isql I always get this error:
# isql -v -3 oracledsn
[HY000][unixODBC][Oracle][ODBC][Ora]ORA-12545: Connect failed because target host or object does not exist
[ISQL]ERROR: Could not SQLConnect
Sadly I can't reproduce it now, but when last trying it I always had
[IM004][unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed
[ISQL]ERROR: Could not SQLConnect
This is the same error message I get from my (proprietary) C++ code, so I'm pretty sure the problem is just the connection settings.
I have checked https://www.connectionstrings.com/oracle/ but none of the combinations work.
Here are all my config settings:
# odbcinst -j -130-
unixODBC 2.3.7
DRIVERS............: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
USER DATA SOURCES..: /home/florian/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
# cat /usr/local/etc/odbcinst.ini
[oraclex]
Description = Oracle ODBC driver for Oracle 19
Driver = /mnt/libsqora.so.19.1
Setup =
FileUsage =
CPTimeout =
CPReuse =
Driver Logging = 7
[ODBC]
Trace = Yes
TraceFile = /tmp/odbc.log
ForceTrace = Yes
Pooling = No
DEBUG = 1
# cat ~/.odbc.ini
[oracledsn]
Driver = oraclex
Server = 10.1.6.19
Port = 1521
Uid = system
Pwd = oracle
Database = orclcdb/orcl/"<empty>"
ORA-12545: Connect failed because target host or object does not exist
I also tried ServerName
ServerName = //10.1.6.19/orclcdb or //10.1.6.19/orcl
[28000][unixODBC][Oracle][ODBC][Ora]ORA-01017: invalid username/password; logon denied
Here's the /tmp/odbc.log:
[ODBC][18832][1564563250.044774][__handles.c][460]
Exit:[SQL_SUCCESS]
Environment = 0x1fd7780
[ODBC][18832][1564563250.044854][SQLSetEnvAttr.c][189]
Entry:
Environment = 0x1fd7780
Attribute = SQL_ATTR_ODBC_VERSION
Value = 0x3
StrLen = 0
[ODBC][18832][1564563250.044886][SQLSetEnvAttr.c][381]
Exit:[SQL_SUCCESS]
[ODBC][18832][1564563250.044914][SQLAllocHandle.c][377]
Entry:
Handle Type = 2
Input Handle = 0x1fd7780
[ODBC][18832][1564563250.044944][SQLAllocHandle.c][493]
Exit:[SQL_SUCCESS]
Output Handle = 0x1fd8090
[ODBC][18832][1564563250.044983][SQLConnect.c][3721]
Entry:
Connection = 0x1fd8090
Server Name = [oracledsn][length = 9 (SQL_NTS)]
User Name = [NULL]
Authentication = [NULL]
UNICODE Using encoding ASCII 'ANSI_X3.4-1968' and UNICODE 'UCS-2LE'
DIAG [HY000] [Oracle][ODBC][Ora]ORA-12545: Connect failed because target host or object does not exist
[ODBC][18832][1564563250.082037][SQLConnect.c][4244]
Exit:[SQL_ERROR]
[ODBC][18832][1564563250.082070][SQLGetDiagRec.c][677]
Entry:
Connection = 0x1fd8090
Rec Number = 1
SQLState = 0x7fffeabcac60
Native = 0x7fffeabcac5c
Message Text = 0x7fffeabcac70
Buffer Length = 500
Text Len Ptr = 0x7fffeabcac5a
[ODBC][18832][1564563250.082092][SQLGetDiagRec.c][726]
Exit:[SQL_SUCCESS]
SQLState = HY000
Native = 0x7fffeabcac5c -> 12545
Message Text = [[unixODBC][Oracle][ODBC][Ora]ORA-12545: Connect failed because target host or object does not exist
I've also been trying out this C code from https://www.easysoft.com/developer/languages/c/odbc_tutorial.html#connect_full - basically the same result.
# cat test2.c
# compile with gcc -I ../include test2.c -o test2 -lodbc
#include <stdio.h>
#include <sql.h>
#include <sqlext.h>
/*
* see Retrieving ODBC Diagnostics
* for a definition of extract_error().
*/
static void extract_error(
char *fn,
SQLHANDLE handle,
SQLSMALLINT type);
main() {
SQLHENV env;
SQLHDBC dbc;
SQLHSTMT stmt;
SQLRETURN ret; /* ODBC API return status */
SQLCHAR outstr[1024];
SQLSMALLINT outstrlen;
/* Allocate an environment handle */
SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
/* We want ODBC 3 support */
SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
/* Allocate a connection handle */
SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc);
/* Connect to the DSN mydsn */
ret = SQLDriverConnect(dbc, NULL, "DSN=oracledsn;", SQL_NTS,
outstr, sizeof(outstr), &outstrlen,
SQL_DRIVER_COMPLETE);
if (SQL_SUCCEEDED(ret)) {
printf("Connected\n");
printf("Returned connection string was:\n\t%s\n", outstr);
if (ret == SQL_SUCCESS_WITH_INFO) {
printf("Driver reported the following diagnostics\n");
//extract_error("SQLDriverConnect", dbc, SQL_HANDLE_DBC);
}
SQLDisconnect(dbc); /* disconnect from driver */
} else {
fprintf(stderr, "Failed to connect\n");
//extract_error("SQLDriverConnect", dbc, SQL_HANDLE_DBC);
}
/* free up allocated handles */
SQLFreeHandle(SQL_HANDLE_DBC, dbc);
SQLFreeHandle(SQL_HANDLE_ENV, env);
}
As another point reference I can connect to said Oracle Dev VM with sqlplus from another machine like this:
./sqlplus sys/oracle#10.1.6.19/orclcdb as sysdba
SQL>
./sqlplus system/oracle#10.1.6.19/orclcdb
SQL>
On the VM I have a file /u01/app/oracle/product/version/db_1/network/admin/tnsnames.ora but I am not completely sure if I also need one on the client?
ORCLCDB=localhost:1521/orclcdb
ORCL=
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
I finally found the solution, although this is for 12.2.0.1 and not 19
# cat .odbc.ini
[oracledsn]
Driver=oracle
UID=system
PWD=oracle
DBQ=192.168.178.32:1521/ORCLCDB
ServerName=//192.168.178.32:1521/ORCLCDB
cat /usr/local/etc/odbcinst.ini
[oracle]
Description = foo
Driver = /mnt/libsqora.so.19.1
Driver Logging = 7
UsageCount=1
FileUsage=1
[ODBC]
Trace = Yes
TraceFile = /tmp/odbc.log
ForceTrace = Yes
Pooling = No
# LD_LIBRARY_PATH=. isql -v oracledsn system oracle
+---------------------------------------+
| Connected! |
I have no Oracle-specific environment variables set, but if it works if I take the value of ServerName verbatim for TWO_TASK.
I had success with oracle 19c, with one minor change here - remove the "//" from ServerName i.e.
ServerName=192.168.178.32:1521/ORCLCDB
I have .NET Core app and we are trying to use Oracle Managed Data Access Client (currently it has beta version only).
However, when I read BLOB from database it gets 'TTC Error'. Does anyone have any ideas how to proceed?
using (OracleConnection conn = new OracleConnection("Data Source=db;User ID=userid;Password=pass;Pooling=False;"))
{
conn.Open();
var sql = "SELECT id, blobdata FROM templ";
OracleCommand cmd = new OracleCommand(sql, conn);
cmd.CommandType = CommandType.Text;
OracleDataReader reader = cmd.ExecuteReader();
using (reader)
{
while (reader.Read()) //TTC Error
{
}
}
"TTC Errror" is main Exception message.
This is not ideal but I ran into this issue today and ended up using the DBMS_LOB.SUBSTR function to read it out in chucks of 2000 (2000 is the largest that RAW can be).
Below is a query that returns a row where each row is 2K chucks of the file at a specific offset.
WITH
INFO
AS
(
SELECT
dbms_lob.getlength(A.FILE_CONTENT) AS FILE_CONTENT_LENGTH,
MOD(dbms_lob.getlength(A.FILE_CONTENT),2000) AS MOD,
CASE
WHEN MOD(dbms_lob.getlength(A.FILE_CONTENT),2000) > 0 THEN TRUNC((dbms_lob.getlength(A.FILE_CONTENT)/2000) + 1)
ELSE TRUNC(dbms_lob.getlength(A.FILE_CONTENT)/2000)
END INTERATION_COUNT,
A.FILE_CONTENT,
A.FILE_ID
FROM TABLE_OF_FILES A WHERE A.FILE_ID = 345321561
)
,OFFSETS AS
(
SELECT
(2000 * (ROWNUM-1)) + 1 AS OFFSET,
I.MOD,
I.FILE_CONTENT_LENGTH,
I.FILE_CONTENT,
I.FILE_ID,
I.INTERATION_COUNT
FROM INFO I
CONNECT BY LEVEL <= I.INTERATION_COUNT
)
,RESULT AS
(
SELECT
DBMS_LOB.SUBSTR(O.FILE_CONTENT, 2000, O.OFFSET) AS CONTENT,
O.OFFSET,
O.MOD,
O.FILE_CONTENT_LENGTH,
O.FILE_ID,
O.INTERATION_COUNT
FROM OFFSETS O
)
SELECT * FROM RESULT R ORDER BY R.OFFSET ASC;
I have created a database file "accounts.accdb" and I'm using the UCanAccess JDBC driver in Eclipse to access it. I can access it fine and update it using my server application but when I close my server application the contents of the database file return to their initial values. My code is below, I have tried using commit() but it doesn't seem to make any difference.
Connection conn=DriverManager.getConnection("jdbc:ucanaccess://accounts.accdb");
//STEP 4: Set auto commit as false.
conn.setAutoCommit(false);
//STEP 5: Execute a query to create statment with
// required arguments for RS example.
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
// Step 6: Execute a SQL SELECT Update.
String sql = "update bankAccounts set " + field + "= " + newValue + " where id = " + id;
System.out.println("update command: " + sql);
stmt.executeUpdate(sql);
System.out.println("Database is updated!!!!");
//STEP 7: Commit data here.
conn.commit();
//STEP 8: Clean-up environment
stmt.close();
conn.close();
I'm using ODP.NET to access Oracle DB from C# .NET.
Please see following code:
OracleConnection con = new OracleConnection();
con.ConnectionString = "User Id=user;Password=pass;Data Source=localhost/orcl";
con.Open();
/* create table */
DbCommand command = con.CreateCommand();
command.CommandType = CommandType.Text;
try
{
command.CommandText = "DROP TABLE TEST";
command.ExecuteNonQuery();
}
catch
{
}
//command.CommandText = "CREATE TABLE TEST (VALUE BINARY_DOUBLE)";
command.CommandText = "CREATE TABLE TEST (VALUE FLOAT(126))";
command.ExecuteNonQuery();
/* now insert something */
double val = 0.8414709848078965;
command.CommandText = "INSERT INTO TEST VALUES (" + val.ToString(System.Globalization.CultureInfo.InvariantCulture) + ")";
command.ExecuteNonQuery();
/* and now read inserted value */
command.CommandText = "SELECT * FROM TEST";
DbDataReader reader = command.ExecuteReader();
reader.Read();
double res = (double) (decimal)reader[0];
Console.WriteLine("Inserted " + val + " selected " + res);
The output from this is always:
Inserted 0,841470984807897 selected 0,841470984807897
But looking at variable values under debugger
val == 0.8414709848078965
res == 0,841470984807897
Why res is rounded up?
I looked into DB and there is stored rounded-up value.
On the other hand I used Oracle SQL Developer to modify this value, and I'm able to store 0.8414709848078965 in database?
I tried types NUMBER, FLOAT(126), BINARY_DOUBLE... always the same result.
Why there is a problem using ODP.NET?
OK, I have found that it works if parameter type is OracleDbType.BinaryDouble. But it causes my code to be dependent of ODP.NET. I wanted to use ADO.NET types (DbType) to achieve my code independency.
Oracle actually has a higher precision for it's numbers than .net!
I tried this in straight Oracle and it works fine, I recommend changing to use a param
e.g.
-- CREATE TABLE TEST (VALUE NUMBER(38,38)); (initial test)
INSERT INTO TEST VALUES (0.8414709848078965);
SELECT * FROM TEST;
VALUE
----------------------
0.8414709848078965
(recommendation)
OracleParameter param = cmd.CreateParameter();
param.ParameterName = "NUMBERVALUE";
param.Direction = ParameterDirection.Input;
param.OracleDbType = OracleDbType.Decimal;
param.Value = "0.8414709848078965";
command.Parameters.Add(param);