Creating a workspace session using SAS IOM & VBA - vba

I am trying to connect to a workspace server using Excel VBA. Using the information on this page, I have produced the following:
Dim obSAS As SAS.Workspace
Dim obWorkspaceManager As New SASWorkspaceManager.WorkspaceManager
Private Sub Form_Load()
Dim obConnection As New ADODB.Connection
Dim obRecordSet As New ADODB.Recordset
Dim obServerDef As New SASWorkspaceManager.ServerDef
Dim xmlString As String
obServerDef.Port = 28561
obServerDef.Protocol = ProtocolBridge
obServerDef.MachineDNSName = "blah.server.com"
Set obSAS = obWorkspaceManager.Workspaces.CreateWorkspaceByServer( "Ref", _
VisibilityProcess, obServerDef, "me#saspw","MyPass", xmlStr)
end sub
My first response was this:
<xml id="combridgeOutput"><connectionAttempts><connectionAttempt>
<sasserver></sasserver>
<sasmachinednsname>blah.server.com</sasmachinednsname>
<sasport>28561</sasport>
<saslogin>me#saspw</saslogin>
<status>0x80041001</status>
<description><Exceptions><Exception>
<SASMessage severity="Error">
The client has connected to a SAS (9.2) Metadata Server (v1.0) when
it intended to connect to a SAS Workspace Server.
</SASMessage>
</Exception></Exceptions></description>
</connectionAttempt></connectionAttempts></xml>
So I updated the port number to point at the workspace server, and now I get this:
<same XML tags as above >
<SASMessage severity="Error">
Client me#saspw does not have permission to use server
SASMeta - Workspace Server (A5DPDN69.AV000069).
</SASMessage>
Would rather not set special permissions for this exercise. How else can one connect VBA to a SAS workspace server session?

Doh! I was using the wrong machine name. For reference, here is the process for getting the correct machine name!
Log into SMC
Expand Server Manager
Expand SASApp
Expand SASApp - Logical Workspace Server
There you will see the correct machine, and will also show the port details..

Related

How to connect Excel to Oracle database?

I am trying to connect Excel to my Oracle database using VBA.
Sub dbConnect()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set con = New ADODB.Connection
Set rs = New ADODB.Recordset
strCon = "Driver={Microsoft ODBC for Oracle}; " & _
"CONNECTSTRING=(description=(address=(protocol=tcp)(host=mydb.domain.com)(port=1522))(connect_data=(sid=mydb))); uid=user; pwd=pw;"
con.Open (strCon)
End Sub
I get an error.
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
I know from other questions and sources that the problem is most likely using the wrong version of the DSN.
However, I don't understand what I need to do to fix it.
My Windows is 64-bit, when I open the ODBC Data Source Administrator I see the following (among others):
Name: Excel Files, Platform: 64-bit, Driver: Microsoft Excel Driver
User DSN
Name: mydb, Platform: 32-bit, Driver: oracle in ORA121020_x86
under System DSN
What can I do to fix it? How do the connection string and the DNSs relate to each other? Should I change the version of one of the DNS and if yes how do I do that?
Edit:
The connection string is copied from the db connection in Oracel SQL Developer where I can access the db.
Ok I managed to fix it. My excel is 64 bit so in order to connect to the db, I had to create a System DNS for my connection that is also 64 bit. In order to do that, I had to go to the /Windows/system32 folder, choose the file odbcad32 and under system DNS add a new DNS with a 64 bit driver I had to download. Lets say I named that DNS abc
I then also changed the connection string that you can see in the above code to
strCon = "Data Source=abc;User=user;Password=pw"
According to this the connection string I used in the post above does not need a DNS, so I don't know why it didn't work, however after creating a new DNS as just described I switched to the new connection string that specifies a DNS.
And voila, after only several hours I was able to connect to my db.
Quick sidenote: As mentioned above, I edited the obcad32 file in /Windows/system32. This is the file for 64 bit DNS. There is a file with the exact same name in the folder /Windows/SysWOW64 that manages the 32 bit DNS, so if you have a similar problem as I had, pay attention to which file you edit.

VBA is unable to create a connection to a remote SQL Database

I've created an excel front end interface to connect with and manipulate an SQL database. I recently received a laptop, and would like to be able to manipulate the data from excel on said laptop. I established a connection using SQL Server Management Studios to the database.
I've tried to update my excel file; however, the VBA code can not connect to the SQL database. I've changed a few of the variables around and set Integrated Security too, but nothing has worked so far. The error message readouts can be seen here:
Here is the code related to the DB connection:
Dim cnSQL As ADODB.Connection
Set cnSQL = New ADODB.Connection
cnSQL.Open "Provider = SQLOLEDB; Integrated Security = SSPI, Data Source = IP Address,Static TP Port; UID = username; PWD =pwd#; Initial Catalog = database"
The error message highlights the second line of code. I'm hoping to be able to connect to the DB from my laptop.
After struggling for a few days, I finally got this to work. There are two important steps you need to take to make excel work with a Remote SQL network. First here is the code used to connect:
Dim cnSQL As ADODB.Connection
Dim ServerName As String
Dim DatabaseName As String
Dim userID As String
Dim password As String
ServerName = "IP Addresss,Port"
DatabaseName = "DB Name"
userID = "username"
password = "pwd"
Set cnSQL = New ADODB.Connection
sqlCommand.ActiveConnection = cnSQL
After I changed the code to this, I got a new error: "optional feature not implemented." To fix this error, I changed the data type of all 'adDate' to 'adDBTimeStamp.' This works for some reason, I don't know why. It works.

How to get the SQL server linked tables are connected to using VBA?

Is there a way to know which SQL Server the linked tables in MS Access database are pointing to using the ODBC connection?
I used the code below but I got the database name only and not the SQL server name.
Private Function checkconn()
Dim strConnect As String
Dim lngLocation As String
strConnect = CurrentDb.TableDefs("dbo_buh_summary").Connect
lngLocation = InStr(strConnect, ";DATABASE=")
If lngLocation <> 0 Then
GetDataPath = Mid(strConnect, lngLocation + 10)
End If
End Function
Assuming you used a FILE dsn to original link the tables?
(or a DSN less). I strong, but rather strong recommend you link always using a FILE dsn (not system or user). The reason is Access converts these links to DSN-less for you automatic. (and thus you don't need to setup a DSN on each computer).
Having noted the above? You can grab the server and the database name with this:
Sub m34343()
Dim strCon As String
strCon = CurrentDb.TableDefs("dbo_tblHotels3").Connect
Debug.Print strCon
Debug.Print Split(Split(strCon, "SERVER=")(1), ";")(0)
Debug.Print Split(Split(strCon, "DATABASE=")(1), ";")(0)
End Sub
Output:
ODBC;DRIVER=SQL Server;SERVER=ALBERTKALLAL-PC\SQLEXPRESS;
Trusted_Connection=Yes;APP=Microsoft Office 2010;DATABASE=test3
ALBERTKALLAL-PC\SQLEXPRESS
test3
So, I in above printed out the connection string, but then the next two lines grabs the server and the database name.

Accessing Oracle SQL Developer database from VBA

New to VBA and returning to SQL after 15 years. I'm am trying to use VBA to run SQL commands to download data into excel for further manipulation.
I have SQL Developer installed on my machine and I am able to access the database using the UI. I have figured out how to connect to the database and run a query within the SQL Developer interface, but honestly, I'm not an IT guy.
Any ideas how to do this? Even basic command line commands to connect to the database and run the query would be helpful.
I found this code on another site, but I'm having trouble getting my connection string to work. My macro errors out on the cnn.Open statement and says the Provider is not installed. I think it's because PROVIDER is set up for a different SQL Database type, but I can't seem to get the connection string to work.
I know my username and password, which I have successfully used to connect in the SQL Developer UI. I'm not sure what to put for remote IP address or database. Would that be the hostname and the SID in the connection properties dialog in SQL Developer? (The hostname looks more like a url without the http than an ip address. Not sure if hostname and ip address is an interchangeable term).
Sub Download_Reports()
'Initializes variables
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim ConnectionString As String
Dim StrQuery As String
'Setup the connection string for accessing MS SQL database
'Make sure to change:
'1: PASSWORD
'2: USERNAME
'3: REMOTE_IP_ADDRESS
'4: DATABASE
ConnectionString = "Provider=ORAOLEDB.ORACLE;Password=PASSWORD;Persist Security Info=True;User ID=USERNAME;Data Source=REMOTE_IP_ADDRESS;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Use Encryption for Data=False;Tag with column collation when possible=False;Initial Catalog=DATABASE"
'Opens connection to the database
cnn.Open ConnectionString
'Timeout error in seconds for executing the entire query; this will run for 15 minutes before VBA timesout, but your database might timeout before this value
cnn.CommandTimeout = 900
'This is your actual MS SQL query that you need to run; you should check this query first using a more robust SQL editor (such as HeidiSQL) to ensure your query is valid
StrQuery = "SELECT TOP 10 * FROM tbl_table"
'Performs the actual query
rst.Open StrQuery, cnn
'Dumps all the results from the StrQuery into cell A2 of the first sheet in the active workbook
Sheets(1).Range("A2").CopyFromRecordset rst
End Sub
I'm needing help with my connection string. Can anyone help me with this?
I'm connecting to a database via Oracle SQL Developer. I am able to connect within the UI by providing the following items:
Connection Name - got it.
myUsername - got it.
myPassword - got it.
Connection Type = Basic, Role = default
myHostname - got it.
myPort - got it.
mySID - got it.
However, I am unable to get my connection string to work in VBA. When I run the script I get
"Run-time Error '3076'. Provider cannot be found.
It may not be properly installed" on the line beginning with cnn.open.

SAS VBA connection

I tried to run a SAS code through VBA. I'm running SAS on a server. I have a test SAS program "Program1.sas" which I've kept on the server. Below is the VBA code that I've used. The SAS code is running but the output dataset is just showing the column headers and the rows are empty.Can anyone help me what could be the possible reason.
Sub Form_Load23()
Dim obObjectFactory As New SASObjectManager.ObjectFactory
Dim obObjectKeeper As New SASObjectManager.ObjectKeeper
Dim obServer As New SASObjectManager.ServerDef
Dim obSAS As SAS.Workspace
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
obServer.MachineDNSName = "xyz"
obServer.Protocol = SASObjectManager.Protocols.ProtocolBridge
obServer.Port = 8871
obObjectFactory.LogEnabled = True
Set obSAS = obObjectFactory.CreateObjectByServer("sas", True, obServer,"userid", "password")
obSAS.LanguageService.Submit ("options source2; %include '/abc/AFP/shikhar.gupta1/amg/**Program1.sas**';")
End Sub'
I believe you have to change the security settings in excel. Find the security settings and protected viewing. The remove all the check marks.
This is an issue on the SAS side. It can happen when your user does not have the metadata 'read' permission on the relevant dataset. It can also happen if your program has an error, and options obs=0; is set.
As #vasilij mentions, use proc printto to write your log to a file system and check for issues, also use SMC to check your metadata permissions.