Focal Point
[SOLVED] How to set server and database with parameter variables for SQL Passthru?

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/1997008036

May 14, 2013, 12:55 PM
J.Hines
[SOLVED] How to set server and database with parameter variables for SQL Passthru?
I'm brand new to SQL Passthru stuff, and not finding a good resource besides this forum for questions.

I have some code working with the basics, but my requirements are to have the server and database as parameters, so I think what I need is something like DEFAULT_DATABASE, similar to the DEFAULT_CONNECTION option, but I can't find any info on how to do this.

My code is:
ENGINE SQLMSS SET DEFAULT_CONNECTION &CONN
SQL SQLMSS PREPARE SQLOUT FOR
SELECT field1, field2
FROM mydb.dbo.myTable
END 


The value for &CONN will be one of the adapters I've already set up in the server console, so I just need to be able to specify the database for that connection now.

If I specify the database "myDB" then it runs fine, and I tried putting a parameter in there (&database) instead, but that results in an error.

I don't care if I have to put the database parameter in the SQL, or in a SET command above, I've just tried every variation I can think of and nothing works.

This message has been edited. Last edited by: J.Hines,



Prod: 8.2.0.4 OS:Windows 10 Output:AHTML, Excel 2007+

The life of a designer is a life of fight against the ugliness.
May 14, 2013, 01:31 PM
Francis Mariani
Try FROM &MYDB...dbo.myTable

When using a Dialogue Manager variable before a period, you need two periods for the variable and one for the existing period. I'm not sure where this is documented...


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
May 14, 2013, 01:45 PM
J.Hines
Wow, Francis, you're the man (once again)!

In everything I've read, that triple period thing never came up. I could understand if you had to put the variable in quotes or something, but that's the first time I've seen the requirement for two periods (outside of the IBM mainframe).

The only thing I found (searching Google for "webfocus two periods") is this document on Parameterizing Master and Access File Values Using Variables:
quote:
In the Access File, concatenate the variables to create the TABLENAME attribute. Note that the separator for between each part is a period, but to concatenate a variable name and retain the period, you must use two periods:

TABLENAME=&db..&usr..&tprf.table&tsuf,

Based on the defaults, the TABLENAME would be:

TABLENAME=mydb.myusrid.test_table


but that doesn't mention three periods, so even if I had read this, I'd still be stuck, so you're a lifesaver!

This message has been edited. Last edited by: J.Hines,



Prod: 8.2.0.4 OS:Windows 10 Output:AHTML, Excel 2007+

The life of a designer is a life of fight against the ugliness.
May 14, 2013, 02:22 PM
J.Hines
So no option though that you (or anyone else) knows of to set the database earlier so I don't have to repeat "&database.." all through my select query?



Prod: 8.2.0.4 OS:Windows 10 Output:AHTML, Excel 2007+

The life of a designer is a life of fight against the ugliness.
May 14, 2013, 02:51 PM
Francis Mariani
I just scannd my SQL passthru code and cannot find any examples of setting the database.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
May 14, 2013, 05:48 PM
Mighty Max
Try this
  
-SET &DataAdapter = 'Reporting';
-SET &DBServer    = 'DEVSQL1';
-SET &DBName      = 'CustomerABC';

ENGINE SQLMSS SET CONNECTION_ATTRIBUTES &DataAdapter &DBServer/,;&DBName
SQL SQLMSS PREPARE SQLOUT FOR
SELECT field1, field2
FROM dbo.myTable
END



WebFOCUS 8.1.05M Unix Self-Service/MRE/Report Caster - Outputs Excel, PDF, HTML, Flat Files
May 14, 2013, 06:01 PM
Waz
You should also be able to use &MYDB|.dbo.myTable


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

May 15, 2013, 09:35 AM
Francis Mariani
Mighty Max, thanks for CONNECTION_ATTRIBUTES syntax.

Documentation says:
ENGINE SQLMSS SET CONNECTION_ATTRIBUTES [connection] server/userid,password [;dbname][:provider_string]


I love the combination of / , ; :


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
May 15, 2013, 09:38 AM
Kevin W
We have found that it pays to end any open sessions before opening a new one (even the first). It's probably overkill before the first session, but doesn't hurt.

-* end any possible previous SQL sessions
ENGINE SQLMSS END SESSION
-RUN

Of course if you need to keep a particular session open for some reason, don't issue the command.


WebFOCUS 7.7.05 (Someday 8)
Windows 7, All Outputs
In Focus since 1983.
May 15, 2013, 02:53 PM
J.Hines
quote:
Originally posted by Mighty Max:
Try this
  
-SET &DataAdapter = 'Reporting';
-SET &DBServer    = 'DEVSQL1';
-SET &DBName      = 'CustomerABC';

ENGINE SQLMSS SET CONNECTION_ATTRIBUTES &DataAdapter &DBServer/,;&DBName
SQL SQLMSS PREPARE SQLOUT FOR
SELECT field1, field2
FROM dbo.myTable
END


I'm having some trouble getting this to work. I have a data adapter with the application-level user ID and password set up already on the server that I want to use, and so wouldn't the server be redundant?

I'm getting the following error:
(FOC1672) SYNTAX ERROR IN SET CONNECTION ATTRIBUTES FOR SQLMSS   INTERFACE
 

Even though my CONNECTION_ATTRIBUTES string matches Mad Max's format exactly (and that of the documentation ). The documentation indicates three different authentication scenarios, none of which seem to be my scenario, which is use the credentials in the Data Adapter.
I just thought about this too, our WF servers are UNIX, not Windows, as it appears the directions above are for, but it doesn't look like the UNIX instructions give me any option to specify the database for a given adapter.



Prod: 8.2.0.4 OS:Windows 10 Output:AHTML, Excel 2007+

The life of a designer is a life of fight against the ugliness.
May 15, 2013, 04:26 PM
Mighty Max
What is the Security of the Data Adapter?
If it is Explicit I believe you are going to have to provide the credentials.

You mentioned your reporting server is Unix. I scanned the documentation you provided.
Looks like you will have to build the JDBC url appropriately. Just do a quick google search for "jdbc sql server url".
  
ENGINE SQLMSS SET CONNECTION_ATTRIBUTES DataAdapter 'jdbc:microsoft:sqlserver://myServer:1433;databaseName=myDatabase'MYUSER,PASS

You can take a look at your server profile (edasprof.prf).
It should have the appropriate syntax for the data adapter connection attributes in the Unix environment. My syntax might be incorrect.

Also open a ticket with IBI Tech Support.

This message has been edited. Last edited by: Mighty Max,


WebFOCUS 8.1.05M Unix Self-Service/MRE/Report Caster - Outputs Excel, PDF, HTML, Flat Files
May 16, 2013, 06:31 AM
J.Hines
The security is explicit. What I don't want to do is have the server password in my focus procedure in clear text.

However, when I look at my adapter, it's like this:
ENGINE SQLMSS SET CONNECTION_ATTRIBUTES myAdapter 'jdbc:sqlserver://serverName:1433'/User,980F27B014D04EBEF8AEBCF6DA952BC4


I'll open a case as well.

So the password there is encrypted. So what I don't know is if I could use that same PW in a procedure, or would it take it literally?

Judging by what the documentation says, I'm thinking not (besides it doesn't mention anything about specifying the database for a UNIX adapter):
quote:
The following SET CONNECTION_ATTRIBUTES command connects to a myServer using the Microsoft SQL Server JDBC Driver, with an explicit user ID (MYUSER) and password (PASS). To ensure security, specify connection attributes from the Web Console, which encrypts the password before adding it to the server profile.

ENGINE SQLMSS SET CONNECTION_ATTRIBUTES CON1
'jdbc:microsoft:sqlserver://myServer:1433'MYUSER,PASS




Prod: 8.2.0.4 OS:Windows 10 Output:AHTML, Excel 2007+

The life of a designer is a life of fight against the ugliness.
May 20, 2013, 10:24 AM
J.Hines
Okay, this was just solved via my case by Michelle. Thanks Michelle.

This works with a UNIX server, connecting to SQL Server databases.
The -RUN and END commands are what makes this work! Otherwise the procedure thinks you're concatenating FOCUS databases.

First, set your default connection to the server you want to use, providing via a variable the name of the data adapter:
ENGINE SQLMSS SET DEFAULT_CONNECTION &server
-RUN


Now we set which database to use (also using a variable):
ENGINE SQLMSS
USE &database
END
-RUN


Then we can run our SQL query and send it to SQLOUT:
SQL SQLMSS PREPARE SQLOUT FOR
SELECT
[fields]
FROM tblWhateverTable t1
JOIN tblAnotherTable t2 on t1.Field = t2.Field;
END

*Note: be sure you terminate your SQL query with an apostrophe, and END.

So, all together:
ENGINE SQLMSS SET DEFAULT_CONNECTION &server
-RUN
ENGINE SQLMSS
USE &database
END
-RUN
SQL SQLMSS PREPARE SQLOUT FOR
SELECT


Then you can just build your report with:
TABLE FILE SQLOUT




Prod: 8.2.0.4 OS:Windows 10 Output:AHTML, Excel 2007+

The life of a designer is a life of fight against the ugliness.
May 20, 2013, 05:50 PM
Waz
Intriguing,

Did they say where it was in the documentation ?

I can't seem to find it.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

May 21, 2013, 02:26 PM
Mighty Max
Its MS SQL Server syntax to specify the database. Its been awhile since I have played with MS SQL Server.
If you had a Oracle database you would need to find the equivalent command.

http://msdn.microsoft.com/en-u...8366(v=sql.105).aspx
http://www.tutorialspoint.com/...-select-database.htm

This message has been edited. Last edited by: Mighty Max,


WebFOCUS 8.1.05M Unix Self-Service/MRE/Report Caster - Outputs Excel, PDF, HTML, Flat Files
May 21, 2013, 06:07 PM
Waz
Oh, so it is.

Doh, should have known that.

Another senior moment.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!