How to set file expiry - azure-data-lake

In Cosmos SCOPE script, we can set the stream/file expiration date using the following code:
OUTPUT Catalog
TO SSTREAM #Output
WITH STREAMEXPIRY #ExpirationInDays;
What is the equivalent syntax in U-SQL?

Right now U-SQL does not provide this option (managing expirations is on our roadmap though). The store just recently introduced the ability to set expiration on files. Please file a feature request at http://aka.ms/adlfeedback and let us know if you prefer it as part of the language or as part of a more policy-based management solution.

Related

How to use SQL Server Reporting Services URL Access to save rendered PDF-Reports as varbinary into Table

I'm trying to store rendered pdf-reports from the Report Server back into a table of the origin database as a varbinary. My current approach would be to use URL-Access inside of an external python script to get the rendered reports and then save them into the corresponding table. The following URL works as expected in the browser:
http://localhost/reportserver?/ReportingServicesTest/Report_Test&rs:Format=PDF
However when I tried to access that URL inside of the external python script I received a 401 error.
So I then tried to use the requests_ntlm library to pass the username and password, but somehow it still doesn't work.
import requests
from requests_ntlm import HttpNtlmAuth
url = 'http://localhost/reportserver?/ReportingServicesTest/Report_Test&rs:Format=PDF'
session = requests.Session()
session.auth = HttpNtlmAuth('Domain\\Username','password')
response = session.get(url,stream=True)
open('C:/Path/Report_Test.pdf', 'wb').write(response.content)
Is my approach in principle correct or are there better ways to accomplish the same thing?
I'm fairly new to SQL Server Reporting Services, so I'm open to your suggestions and appreciate your help in advance.
IMHO if you need to historic data for safekeeping or auditing purposes I'd strongly recommend to keep the data in the database. Use a staging environment to add a timestamp to the report data so the snapshots make more sense. In this way you can use the SSRS portal later on to filter on a particular historic version (parameterized) and you don't have to build a bespoke PDF viewer. It would also save some database storage. As an alternative, you could create a subscription in SSRS, have the PDF send to a file share. Then configure a listener to that directory to get your meta information and store that reference in a database table. Needless to say I'm not a big fan of storing files in the database as file storage is cheaper than database storage most of the time.
To solve your authentication issue you might want to check up on your rsreportserver.config file on your web server as your current code suggests that your local host is unknowing of any domain. In any case you can try changing your <Authentication/> section so that it looks like this:
<Authentication>
<AuthenticationTypes>
<RSWindowsBasic>
<LogonMethod>3</LogonMethod>
<Realm></Realm>
<DefaultDomain>putyourfullyqualifieddomainnamehere</DefaultDomain>
</RSWindowsBasic>
</AuthenticationTypes>
<RSWindowsExtendedProtectionLevel>Off</RSWindowsExtendedProtectionLevel>
<RSWindowsExtendedProtectionScenario>Proxy</RSWindowsExtendedProtectionScenario>
<EnableAuthPersistence>true</EnableAuthPersistence>
</Authentication>
This will also work if your web server is behind a proxy or firewall.
Important: the content of DefaultDomain should be a FQDN, such as contoso.microsoft.com or myprimarydomain.lan

Logging a parameter in SQL Server

I'm using C# and asp.net with SQL Sever 2012 and want to log an environmental signals on a database (like temperature or humidity). I want to retrieve logged information to make reports and create charts. In your opinion what's the best method to do the job?
Thanks in advance
Go to this example hope it shall be helpful
http://stevenjohnston.co.uk/2012/12/12/net-gadgeteer-temperature-logger-example/

create pdf files in sql server

All of our correspondence is done via database mail in sql server. The data for document generation and the rules to trigger the generation are all on sql server. We now have to create a pdf file. I was planning on using pdfsharp/migradoc to do it, but then we'd have to create document and time its readiness with sql server data state and mail state. It'd be nice if the db could handle everything.
Has anyone created pdf files directly in sql server? And if so, how.
take a look here: Create data driven PDF on the fly by using SQL server reporting service (SSRS)
I've not used it, but there is SQL2PDF stored proc. It uses sp_OA% code.
Google search
Blog article and duplicated on SQL Server Central (needs login)
SQL isn't the best place to do this of course, but if you have to I'd use CLR if possible.

How to set SSIS Http Connection Manager credentials with config file?

Within an SSIS package I have a Web Service task which uses an Http Connection Manager. I need to set credentials for the connection so that it will authenticate with the remote web service. I can set these at design time, however I would like these credentials to be provided to the package using an XML package configuration file.
The problem is that the credentials for the connection do not appear among the properties that can be configured. I have tried setting this programmatically, but I cannot seem to access the credentials that way either:
Dim webConnMgr As ConnectionManager = Dts.Connections("My web service")
Dim webConn As Wrapper.ConnectionManagerHttpClass = _
CType(webConnMgr.InnerObject, Wrapper.ConnectionManagerHttpClass)
webConn.?
Any ideas?
SQL 2005 has very limited member properties for the ConnectionManagerHttpClass. Thankfully it has been addressed in SQL 2008 :)
MSDN - SQL 2005 ConnectionManagerHttpClass properties.
VS.
MSDN - SQL 2008 ConnectionManagerHttpClass properties.
According to this MSDN link, the public class [ConnectionManagerHttpClass] implements IDTSConnectionManager90, ConnectionManagerHttp.
Since we will assume you are using SQL 2005 (according to your Stackoverflow tags), you may want to check out the IDTSConnectionManager90.ConnectionString Property on MSDN as well.
Also check out the ConnectionManagerHttpClass.ConnectionString Property on MSDN, which implements IDTSConnectionManager90.ConnectionString and is overridable.
This should point you into the right direction. May the farce be with you.
Sounds like you need to assign the values in the configuration file to a variable in your package. You can then access the variable from your script task (Dts.Variables("VariableName").Value.ToString if I remember rightly!).
I have found no way to specify the credentials using a configuration file, or programmatically, but a workaround is to simply save all the credentials (as set in the designer) in the package, and then have different copies of the package for each different configuration. This is done by setting the ProtectionLevel of the package to, for example, EncryptSensitiveWithPassword.
This is obviously not ideal.
SQL2008 SSIS exposes these properties correctly; unfortunately 2005 is the environment I have to work with. I have worked around the problem by developing a custom component which allows the properties to be set.
this can be done by setting protection level to EncryptSensitiveWithPassword, and run the ssis with decrypt option

Copy a file from one dir to another by date

I have this SQL Job (in SQL Server 2005) that creates a backup every six(6) hours, the backup's filename is based on the timestamp so that it will create a unique filename(dbname_yyyymmddhhmmss.bak), Now my question is, How would I know using xp_cmdshell if the file is three day old and based on my script I want to delete backup(.bak) that is a three day old. Can someone out there help me, thanks in advance. Cheers!
I agree that xp_cmdshell is not the best alternative for the job. If you're like me and you don't like/trust maintenance plans, you can probably write a C# console application, where file system support is much stronger than what you can do in DOS (or using T-SQL to parse the output of xp_cmdshell 'DIR ...'), and then schedule that in a windows scheduled task so that you don't have to worry about escalation of privileges from the SQL Server service/proxy account. While it's nice to put everything in one package, you don't always want the guy who changes your oil to make you a quiche.
This is not really the answer to your questions, but you could do this directly in SqlServer 2005 with a Maintenance Plan (Object Explorer -> Management -> Maintenance Plans).
I usually create one Maintenance Plan including two tasks: One "Maintenance Cleanup Task" which deletes old backups after x days, followed by a "Back Up Database Task".
This is not really a task that is suited to xp_cmdshell. Enabling this feature within SQL Server also has security implications.
What you are looking to achieve would be much better suited to SQL Server Integration Services (SSIS). There are components available that can be used to manage and perform your backups, as well as File System Task components that can be used to move and delete data.
You could use a combination of a File System Task, variables and expressions in order to retrieve the backup filename, extract the date component and determine how old the file is. You can then take appropriate action on the file.
I hope this helps but please feel free to pose further questions if you require additional information.
Cheers,John
You could write a .NET assembly and call it from within SQL Server. It would be fairly easy to write it so that a table valued function returns all of the files in a certain directory with filename and file datestamp.