Encrypt query string in SQL possible? - sql

please give me some advice. I have to send email using SQL database mail. In my email, I have to create links that a user can click to go to a product page on my site. However, I need to encrypt the ID of the product and once the product page load, the querystring of the product ID will be decrypted.
How can I get the encryption algorithm which I created in web site class into SQL? I believe the decryption and encryption algorithm must be the same, so that my page can decrypt correctly when the user click on the link in their email. The encryption class I use is something similar to this link: http://www.codeproject.com/Articles/33350/Encrypting-Query-Strings
Thanks a lot for your help.
PS: I also posted this question on asp.net forum.

You can run CLR (ie .NET) code within SQL Server. There are several steps involved, but it starts with creating an "SQL Server" project within Visual Studio, writing the code, and deploying it to your SQL Server. You also have to enable CLR functions within SQL Server using sp_configure.
See here (MSDN) for detailed instructions: How to: Create and Run a CLR SQL Server User-Defined Function .

After doing quite some research, I can confirm that CLR is the way to go. As suggested, I used user defined function CLR. First I need to create CLR project in visual studio. Here is a good starting point to understand how it works:
http://blog.sqlauthority.com/2008/10/19/sql-server-introduction-to-clr-simple-example-of-clr-stored-procedure/
Then instead of adding a CLR stored procedure I move to User defined function. Add an encryption class and called the class in the user defined function. Build and Deploy. That's it.
Here is another useful links:
http://channel9.msdn.com/Learn/Courses/SQL2008R2TrainingKit/CLR/CLRIntegrationLab/Exercise-1-Creating-User-Defined-Functions-Using-SQL-CLR
Thanks dbaseman for pointing that out.

Related

Which software/framework to use to create App for Call Calibration for Quality Dept

I'm not sure if this is the right place to ask this question. If not, please direct me to the right place.
We used to have an application that was created using VB and Microsoft Access. It was an application to score calls from Agents and would then run a few calculations and grade those agents based on a few algorithms.
We replicated all that Access data onto SQL but for some reason, we were just not able to connect the VB application to the SQL Database instead. The application was also outdated and we needed a change.
Can anyone suggest software/framework that can be used to create a new application with an ability to connect to a SQL database?
EDIT: We have a Microsoft Office 365 subscription. I was thinking of using PowerApps. I've never used it before. Does anyone think this could help serve my purpose?
I have extensive experience of using PowerApps to create applications connected to SQL Server (in my case Azure SQL Database), and am mostly satisfied.
There are some constraints, but not major. Please see these posts for some further information.
I would suggest PowerApps if you have Office365.

Connecting to SQL server through a script and automatically generate data and sent to user as an email

I am working on one concept to reduce the routine work where we query to generate data and sent to client. Can this be possible?
My total query:-
Is there a possibility like to use a script that connects to SQL server and executes a query to generate data and send the data to the user in the form of email with the file attached preferably an .XLS or .XLSX or .csv format.
But the user who is running the script is not having any sql related installed on his machine.
Can someone advise me.
Thank you.
Best regards
You can do this entirely with Sql Server, as an agent job.
If you need this for some reason to run on the end-user's own machine, you can do it via a Powershell script or vbscript that you call from a Scheduled Task. You will need the Sql Server Native Client installed on the machine for this to work, but if that user does anything at all that talks to the database (like use an database driven application) then they likely already have this.
My suggestion is almost similar to the Joel Coehoorn gave you. Also you can find a PowerShell script for emailing in my blog article. As far as I understand you want to automate it all.
Of course you'll have to modify it a little bit, to fit your needs. But the logic is there. If you still have some questions about it, please just ask.
UPDATE
I don't see why not. But since I'm familiar with PowerShell, I'll suggest you the similar solution as described in this article. Pseudo code for sample workflow:
SqlClient.SqlConnection -->
$command.CommandText = $query -->
| Out-File C:\..\result.txt -->
send-mailmessage -Attachments "C:\..\result.txt"
According to MSDN the sqlcmd script supports more complex logic than Transact-SQL scripts. About emailing part - look here. Please note that you'll most probable need the SMTP server details from your admins.

How do I upload an Excel sheet to a SQL table in a Lightswitch web client?

I have a lightswitch project in visual studio 2013, using vb.net. I would like the user to be able to click a button and have lightswitch find an excel file, and upload that file to a sql table according to a pre-determined column mapping.
My preference was to use the Office Integration extension for visual studio, which I got working with VS 2013 by downloading it from this link: http://www.ge.tt/71iuRQv/v/0
However, the documentation and examples for office integration seem to be very heavy on getting an excel spreadsheet into a display in the lightswitch web client, rather than into the sql data table, which is where I need it. Here are the examples I've been following:
http://blogs.msdn.com/b/bethmassi/archive/2012/07/18/new-and-improved-office-integration-pack-extension-for-lightswitch.aspx
Alternatively, I have an existing stored procedure, and I can request that the server call this stored proc by sending a web API extension from the client to the server. I have this working already for other stored procs, according to examples from Beth Masi and Paul van Bladel. (Stackoverflow won't let me post the links...)
The undesirable part of this approach is that the stored proc is old, and messy.
I've searched and searched, but have yet to find anyone approach this problem for VS 2013 with lightswitch. Any useful advice?
I've used the method detailed by Matt Sampson to store word files and it works very well. Since it just stores the raw binary it should handle Excel files just as well.
If you're creating the table in LightSwitch, use the Binary Type. If you use SQL create scripts use varbinary(MAX).
You need to create a custom Silverlight dialog box to gain access to the OpenFileDialog object. Then open the file in as a FileStream.
Finally, you need to add a handler for the closed method of the control and then show the control to the user. Most likely done in a button. This needs to be done on the main dispatcher.
The code examples are in C# but I just used one of the many available translators out on the web and copy/pasted the VB.NET code.
Another option might be to consider shelling out to the DTSEXEC run-time to execute an SSIS package to perform the upload - especially if the target Excel spreadsheets have predefined layouts and content data types.
Even simpler, you might be able to use the SQL Server BULK INSERT command to get the job done - although that would require a SQL Client connection to your database.
HTH

SSRS 2008 - reportservices.asmx not compatible with legacy app

We have acquired an application that was written approximately 2003. Part of the app uses SQL Server Reporting Services to generate PDFs of reports. Basically within the app a user clicks a button, modifies parameters (start/end date) and a report is passed back (i think) in PDF format so that it can be printed. Great. Works fine in SQL 2005.
However, SQL 2008 is another beast entirely. I can run the same report from the web interface (http://127.0.0.1/reports/...). But the URL doesn't work. I dug around and found that the app is sending a call to 127.0.0.1/reportserver/reportservice.asmx. Now it returns an empty string instead of the XML document.
Supposedly there is a 2005 compatible version called reportserver/reportexecution2005.asmx but that generates a whacky SOAP error. "System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: http://schemas.microsoft.com/sqlserver/2003/12/reportingservices/Render. at System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouterRequest() ....
I notice now when I try to use internet explorer and browse to 127.0.0.1/reportserver/reportservice.asmx i get a login prompt, whereas that was not the case with SSRS 2005. I also notice that if I browse to reportserver/reportexecution2005.asmx it returns a XML page which seems mostly similar to what was returned in SSRS 2005.
So obviously I am missing something. I think since the app was created a while ago I should be using the SQL2000 version which is 127.0.0.1/reportserver/reportservice.asmx. But I think now there is an authentication error.
Anyway. I'm clueless. Anyone have any thoughts? Thanks.
We don't have the source code to the app, but I can modify the connection parameters, like I can ask it to query for ReportServiceXXX.asmx instead of ReportService.asmx
You are very close to seeing the problem. If you look closely at the XML from ReportExecution2005.asmx you will see that it is in Soap12. Your error message shows that a call was made using method System.Web.Services.Protocols.Soap11ServerProtocolHelper.RouterRequest, which is sending a Soap11 message. I am having the same problem, but have not solved it yet.
My two options are to either add a binding to SQL 2008 report service to accept Soap11 or modify my code to send Soap12. I am hoping for a simple config change in SQL server, but have not found it yet.

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