Accessing oracle DB through SAS - oracle

I am trying to access oracle server (I use sqldeveloper) through SAS studio and not able to figure out the right path
libname oralib clear;
libname oralib oracle path=? user=myuserid password=mypass connection=global;
I am not sure what the path must contain
(I have the following info of the oracle DB - hostname, service name and port)
Any help would be appreciated.

The documentation page that should help you is Libname - Oracle:
If you have a path alias already created (service name), you can refer to it with the language you use above:
libname mydblib oracle user=myusr1 password=mypwd1 path=mysrv1;
There, mysrv1 is the alias defined for the path you have defined; most commonly those are defined in tsnames.ora. See this Oracle documentation for the relevant information as to how to define those.
You can also explicitly provide the information like so:
libname x oracle user=myusr1 pw=mypwd1
path="(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP) (HOST = pinkfloyd) (PORT = 1521))
)
(CONNECT_DATA =
(SID = alien )
)
)"
;
However, if you already use SQLDeveloper, you may already have a tsnames.ora file and are best off using that, as if you have to update things from that file you will want to do it only once, not in both your SQLDeveloper and your SAS code.
Since you say you already have the service name, this is the name that would go in path by itself.

Related

Failed to run spark query in databricks notebook after storage configurations

I already set up key vault scope in the notebooks and I established the connection to the storage account using the following steps:
spark.conf.set("fs.azure.account.auth.type."+StorageAccountName+".dfs.core.windows.net", "OAuth")
spark.conf.set("fs.azure.account.oauth.provider.type."+StorageAccountName+".dfs.core.windows.net","org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider")
spark.conf.set("fs.azure.account.oauth2.client.id."+StorageAccountName+".dfs.core.windows.net",clientId)
spark.conf.set("fs.azure.account.oauth2.client.secret."+StorageAccountName+".dfs.core.windows.net",clientSecret)
spark.conf.set("fs.azure.account.oauth2.client.endpoint."+StorageAccountName+".dfs.core.windows.net","https://login.microsoftonline.com/mytenantid/oauth2/token")
The values of "StorageAccountName", "clientId", "clientSecret" all come from key vault and I am able to get their value properly. In my storage account access control I also assigned the
Storage Blob Data Contributor role to my service principal.
After these configurations, I assigned a connection variable:
var apptable = "abfss://container#"+StorageAccountName+".dfs.core.windows.net/path/to/data"
If I run the following command, I am able to see the files in the blob storage
display(dbutils.fs.ls(apptable))
I am also able to check the schema:
var df = spark.read.format("delta").load(apptable)
df.printSchema()
but if I tried to run the following query:
var last_appt = spark.sql(s"""select max(updateddate) from apptable""").collect()(0).getTimestamp(0)
I got the error:
KeyProviderException: Failure to initialize configuration
Caused by: InvalidConfigurationValueException: Invalid configuration value detected for fs.azure.account.key
I researched online and seems there are some issues in the spark configs. But if it failed to get access to the storage, how come the above display command is running well? What could be possibly missing in such scenario?
I have limited experience on databricks. Appreciate any help.
I tried to reproduce the same in my environment and got the below results and I configure same as mentioned above.
Please follow below code:
Read spark dataframe df.
var df = spark.read.format("delta").load(apptable)
Create temp table:
%scala
temp_table_name = "demtb"
df.createOrReplaceTempView(temp_table_name)
Now, using below code. I got this output.
%scala
val aa= spark.sql("""select max(marks) from demtb""")
display(aa)
Update:
As mentioned, in below comment its working fine for me.
df1.write.mode("overwrite").format("parquet").option("path","/FileStore/dd/").option("overwriteschema","true").saveAsTable("app")
And also, you can try this syntax for configuring azure gen2.As per requirement you can change file format. For demo I'm using csv.
spark.conf.set("fs.azure.account.key.<storage_account_name>.dfs.core.windows.net","Access_key")
Scala
%scala
val df1 = spark.read.format("csv").option("header", "true").load("abfss://pool#vamblob.dfs.core.windows.net/")
display(df1)
Python
df1 = spark.read.format("csv").option("header", "true").load("abfss://pool#vamblob.dfs.core.windows.net/")
display(df1)

How to make forked GORM v1 print full path logs?

Screens:
Now
Earlier
We've had to fork https://github.com/jinzhu/gorm (gorm v1) because of database driver. And now gorm prints logs without full log path. You can see details in screenshots.
How can we make correct output from the gorm logs?
$GOPATH/src/your_git.com/test/gorm/utils.go
var goSrcRegexp = regexp.MustCompile(`jinzhu/gorm(#.*)?/.*.go`)
var goTestRegexp = regexp.MustCompile(`jinzhu/gorm(#.*)?/.*test.go`)
replace jinzhu/gorm with your own

RSQLite does not create local database

Reprex:
con <- DBI::dbConnect(RSQLite::SQLite(), path = "test.sqlite")
dbWriteTable(con, "mtcars", mtcars)
dbListTables(con)
[1] "mtcars"
dbDisconnect(con)
When I come back:
con <- DBI::dbConnect(RSQLite::SQLite(), path = "test.sqlite")
dbListTables(con)
character(0)
I thought dbConnect should create a database if none exists. I don't know what is going on.
To create a local database you still need to supply parameters specific to your machine. This fixed the issue for me:
con <- DBI::dbConnect(RSQLite::SQLite(),
user = 'root',
password = '',
dbname = 'test.sqlite',
host = 'localhost')
This is documented poorly if you do not have much understanding of SQLite databases. It seems a database was only being created in memory. Maybe someone else can expound on this as I think warnings would help guide users in this situation.

Linking to Oracle tables in Access using VB6: Error 3000?

I am trying to link an Oracle table to access using the following Visual Basic 6.0 code:
Dim objApp, objDB, objTable As Object
Dim strFile, strConnect, strLocalTable, strServerTable As String
strFile = "C:\path\to\base.mdb"
strLocalTable = "local"
strServerTable = "BASE.TABLE_NAME"
strConnect = "ODBC;Driver={Microsoft ODBC for Oracle};ConnectString=name.world;Uid=username;Pwd=password;"
Set objApp = CreateObject("Access.Application")
objApp.OpenCurrentDatabase strFile
Set objDB = objApp.CurrentDb()
Set objTable = objDB.CreateTableDef(strLocalTable)
objTable.Connect = strConnect
objTable.SourceTableName = strServerTable
objDB.TableDefs.Append objTable 'Generates 3000 Error
objDB.TableDefs.Refresh
On the second to last row I get (loosely translated from swedish by me) "Run time error 3000: Reserved error (-7778). There is no message for this error."
Any ideas on why this may be? I am told this code has worked before, so it could possibly be some kind of version conflict with updated software. The database is in Access 2000 format, and Access 2013 is installed on the computer (however, saving the database as Access 2013 does not help). Or is there something wrong with the connection string perhaps?
EDIT: I tried using a DSN in the connection string:
strConnect = "ODBC;Driver={Microsoft ODBC for Oracle};DSN='test';"
I get the same error, even though I can use that very DSN to link the tables manually in Access.
Also (as I stated in the comments) changing some of the information in the connection string (like deliberately providing an incorrect username) leads to a different error (3146: Connection failed). This leads me to believe that the connection to the database works, since it seems to be able to differentiate between good and bad credentials.
Try this connection string and leave out the 'world.' part
ODBC;DRIVER={Oracle in orahome32};UID=userId;PWD=password;SERVER=servername;dbq=servername
(I was having trouble earlier today with connections that left the dbq out)
Or maybe your existing one will work, but regardless...I think Access likes you to create the table default in one swoop and not break things up so.....
Instead of this:
Set objTable = objDB.CreateTableDef(strLocalTable)
objTable.Connect = strConnect
objTable.SourceTableName = strServerTable
Try This:
Set objTable = objDB.CreateTableDef(strLocalTable, dbAttachSavePWD, strServerTable, strConnect)
(NOTE: the dbAttachSavePWD will help avoid users getting prompted for password every time they touch the table; leave it out if that is not desired)

Connection refused Oracle DB [duplicate]

I have a Java application that uses JDBC (via JPA) that was connecting to a development database using hostname, port and Oracle SID, like this:
jdbc:oracle:thin:#oracle.hostserver1.mydomain.ca:1521:XYZ
XYZ was the Oracle SID. Now I need to connect to a different Oracle database that does not use a SID, but uses an Oracle "Service Name" instead.
I tried this but it doesn't work:
jdbc:oracle:thin:#oracle.hostserver2.mydomain.ca:1522:ABCD
ABCD is the Service Name of the other database.
What am I doing wrong?
http://download.oracle.com/docs/cd/B28359_01/java.111/b31224/urls.htm#BEIDHCBA
Thin-style Service Name Syntax
Thin-style service names are supported only by the JDBC Thin driver. The syntax is:
#//host_name:port_number/service_name
For example:
jdbc:oracle:thin:scott/tiger#//myhost:1521/myservicename
So I would try:
jdbc:oracle:thin:#//oracle.hostserver2.mydomain.ca:1522/ABCD
Also, per Robert Greathouse's answer, you can also specify the TNS name in the JDBC URL as below:
jdbc:oracle:thin:#(DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL=TCP)(HOST=blah.example.com)(PORT=1521)))(CONNECT_DATA=(SID=BLAHSID)(GLOBAL_NAME=BLAHSID.WORLD)(SERVER=DEDICATED)))
So there are two easy ways to make this work. The solution posted by Bert F works fine if you don't need to supply any other special Oracle-specific connection properties. The format for that is:
jdbc:oracle:thin:#//HOSTNAME:PORT/SERVICENAME
However, if you need to supply other Oracle-specific connection properties then you need to use the long TNSNAMES style. I had to do this recently to enable Oracle shared connections (where the server does its own connection pooling). The TNS format is:
jdbc:oracle:thin:#(description=(address=(host=HOSTNAME)(protocol=tcp)(port=PORT))(connect_data=(service_name=SERVICENAME)(server=SHARED)))
If you're familiar with the Oracle TNSNAMES file format, then this should look familiar to you. If not then just Google it for the details.
You can also specify the TNS name in the JDBC URL as below
jdbc:oracle:thin:#(DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL=TCP)(HOST=blah.example.com)(PORT=1521)))(CONNECT_DATA=(SID=BLAHSID)(GLOBAL_NAME=BLAHSID.WORLD)(SERVER=DEDICATED)))
Try this: jdbc:oracle:thin:#oracle.hostserver2.mydomain.ca:1522/ABCD
Edit: per comment below this is actualy correct: jdbc:oracle:thin:#//oracle.hostserver2.mydomain.ca:1522/ABCD (note the //)
Here is a link to a helpful article
This discussion helped me resolve the issue I was struggling with for days. I looked around all over the internet until I found the answered by Jim Tough on May 18 '11 at 15:17. With that answer I was able to connect. Now I want to give back and help others with a complete example. Here goes:
import java.sql.*;
public class MyDBConnect {
public static void main(String[] args) throws SQLException {
try {
String dbURL = "jdbc:oracle:thin:#(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=whatEverYourHostNameIs)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=yourServiceName)))";
String strUserID = "yourUserId";
String strPassword = "yourPassword";
Connection myConnection=DriverManager.getConnection(dbURL,strUserID,strPassword);
Statement sqlStatement = myConnection.createStatement();
String readRecordSQL = "select * from sa_work_order where WORK_ORDER_NO = '1503090' ";
ResultSet myResultSet = sqlStatement.executeQuery(readRecordSQL);
while (myResultSet.next()) {
System.out.println("Record values: " + myResultSet.getString("WORK_ORDER_NO"));
}
myResultSet.close();
myConnection.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
In case you are using eclipse to connect oracle without SID. There are two drivers to select i.e., Oracle thin driver and other is other driver. Select other drivers and enter service name in database column. Now you can connect directly using service name without SID.
When using dag instead of thin, the syntax below pointing to service name worked for me. The jdbc:thin solutions above did not work.
jdbc:dag:oracle://HOSTNAME:1521;ServiceName=SERVICE_NAME
This should be working: jdbc:oracle:thin//hostname:Port/ServiceName=SERVICE_NAME

Resources