SSRS - Send an email based on the query - sql-server

I have a query that produces results of a user's email address and their computer depending on how long they have not turned their computer on. IE if the user has not turned their computer on in 20+ days the query will produce:
host_name //user_name //user_email //Time Stamp //Time //Todays-Date //DateDiff
My question is based on the user's email I would like to send an email or even better a teams message to the user to get their computer(usually a laptop) onto the internet so that it will be updated via config manager.
I was thinking SSRS, power automate, or a powershell script but I am at a loss as to where to begin.

In case you decide to go with ssrs. I would split the string to extract user's email in sql code and do data driven subscription with email as destination. The email returned from query would be passed to To variable.

Related

Embedding username and password in Excel Microsoft Data Query so other users can refresh data

My company is using Tableau for Served data, but I have user who want Excel text table type data served - Text Tables with many columns, >100k Rows, color conditional formatting - which Tableau deals horribly with.
Everyone also has Excel, so I thought that I could set up an Excel file to pull the data from the SQL Server and be refreshed on demand by the users. I had found an article here about using Microsoft Query within Excel to access the data source.
In Sql Server, I have a scheduled stored procedure that performs a nightly refresh of a results Table I have created I'll call that Table "[Server].[dbo].[Results]". This is the Table that I was trying to display in Tableau - and everyone would have been able to access it, but it runs so slow, it is worthless.
I created the same thing in Excel, and it loads or refreshes data from [Server].[dbo].[Results] in < 30 secs with ~30 columns and > 100k rows with lots of colored conditional formatting. It works great.
So, for Excel, I had our IT department create a user account that only has read-only access to the [Results] Table - that account does NOT have access to anything else in the Server Databases. The credentials are something like Username = "ResultsUser" and Password = "ResultsPassword". Again - EVERYONE would have had read-only access to this data if I could have gotten Tableau to work, so we don't care who knows this UserName and Password. In my Excel file, I used these credentials when I created the Data Connection to [Server].[dbo].[Results], and I DID select "Save Password" for the Connection String
It refreshes fine for me on my work computer over our VPN, but when I sent the file to my user, she cannot refresh the data on her work computer over the VPN. If I dig into the Connection Properties, even though I can see embedded "ResultsUser" and "ResultsPassword" in the Connection String, I also can see MY Windows UserID listed for the WSID. Not sure if this is what is preventing my user from being able to refresh.
Some places I read, it sounds like the embedded credentials, just make it so the creator of the file (me) doesn't have to enter username and password when they refresh the data. What I need is - with ResultsUser and ResultsPassword credentials embedded in the file - ANY USER of the Excel file can refresh the data - as long as they are on the network.
Does anyone know if this is possible? Is there something I am missing? Do I need to use some other technique?
Thanks in advance,
MikeC

Email Router - when updating Mailbox's email address returns SQL timeout error

I have an on-premise CRM 2016 instance and I can't receive any incoming emails inside of it even though when I run the test access says everything is good.
First, I'm unable to change a queue record email address, because I keep getting a SQL timeout error (doesn't matter how much time you increase the timeout it will never change) but if I try to change any other field it works and saves (but not the email field of course).
The same with the Mailbox's records, when I try to change the email it returns a SQL timeout error.
So what I did was change these emails by SQL queries, but after that the emails still won't create inside CRM.
It shows the next warning log in the event viewer:
35241 - The recipients for the email message with subject "[x]" in mailbox [email address] did not match any known records.
I'm running out of choices here, when I run the diagnosis tool on my organization it's performance is good but there must be something obstructing the communication with the SQL? Any clues?
SQL timeout error:
Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: SQL timeout expired.Detail:
-2147204783
SQL timeout expired.
2018-10-10T14:14:15.5749939Z
I got the answer from Microsoft Community Forumns, thanks to Radu Chiribelea:
It's not enough to change the email address in SQL in it's base table for a record, so that this can be used for email tracking. There are other references as well - for example the EmailSearchBase. This is why you need to let the platform handle your changes.
You biggest issue here is the SQL Timeout and that is what you need to address. Since this occurs at a Create / Update I suspect there might be a deadlock somewhere. Do you have any plug-ins or workflows triggered at the time you create / update? If you disable those, do you still see the issue?
Can you enable a CRM Platform trace at a Verbose Level while reproducing the issue? This would give you a better overview of the actual timeout and you can then start from there to tackle it.

How to send automatic email notification to user before two months expire date

I had two columns in my database table in SQL Server i.e start-date and expiry-date. When user subscription going to end before two months where it needs to send automatic email to user regards your subscription going to end please renew subscription. how to write stored procedure in SQL Server
To That You Need to Define A job which contains your business using SQL Server Agent Link Below :
https://learn.microsoft.com/en-us/sql/ssms/agent/schedule-a-job?view=sql-server-2017
Inside the Job you need to setup the email :
https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-send-dbmail-transact-sql?view=sql-server-2017
Here is Also tutorial step by Step : https://www.brentozar.com/archive/2014/10/send-query-results-sql-server-agent-job/.
The other main point should you do that ?
One of main concepts in software development is Separation of concerns. Where each layer is responsible for doing specific thing and does it well.
So if your Project has another layers, notifications should be in another layer not in DB level as Mentioned by Andrew in the comments.

How to link and ODBC table to MS Access database using VB and without connecting to the server?

I have a VB procedure that changes a connection string for all 360 linked tables in my Access 2002 database. If I run this procedure using an SQL server in my local network, it runs about 30 seconds. The problem is that I have to use an SQL server somewhere in the Internet. In this case the procedure runs for about 5 minutes.
The question is - how can I prevent Access from connecting to the server to check every table I re-connect?
An alternative question (maybe more correct).
I need to run that re-connection procedure on every user's computer every time I give them a new version of the database, to save user's login and password into every linked table. Maybe there is some other way to set the username and password for the ODBC connection?
Linked tables do NOT all of a sudden decide to connect to some some server. So the recommend approach here is to link the tables once (and leave the password + user name OUT of the link).
Then on startup, all you do is execute ONE logon command and then ALL OF THE tables are instant available and able to be used WITHOUT any re-link or re-fresh of the conneciton string. Same goes for any pass-ghouth queries etc.
So the existence of a linked table IS NOT USED on startup and you can have 3 or 300 linked tables and launch Access WILL NOT cause a connection to occur “unless” you decode to do something like a re-link.
Bottom line:
You don’t and should not re-link on startup
You do not need to include the user name + password in the table links.
A ONE TIME logon at startup will cause Access to “cache” the user name + password and this will be used for ALL CURRENT EXISTING table links. The beauty of this is when the user exits the applctaion then no passwords etc. are stored in the linked tables.
So you cannot prevent access from connecting to the server during a table re-link since that what it must do.
However there is LITTLE if not ZERO reason to re-link every time on startup? Why are you doing a re-link are startup?
I need to run that re-connection procedure on every user's computer every time I give them a new version of the database,
Why not link the database on your machine BEFORE you distribute it to that user? After all the connection is over the internet – so you should be able to link to that database system from your development computer. And assuming you cannot, then ok, perhaps you might beforced to do a ONE time re-link. Try the re-link with a cached logon – it likely will run faster, but then again it will only be a one time re-link anyway.
save user's login and password into every linked table.
NO NO this is NOT required nor is recommended. If a user holds their mouse over a linked table then if you included the user name + password it is in plan view.
You DO NOT want to include the user name + password in each linked table. How to execute a SINGLE logon and have that logon used for ALL tables (without a re-link) and for ALL tables EVEN without the user id + password saved is outlined here:
Power Tip: Improve the security of database connections
http://blogs.office.com/b/microsoft-access/archive/2011/04/08/power-tip-improve-the-security-of-database-connections.aspx

Transmitting sessions id from SQL Server to web scripts

I have a bunch of stored procs doing the business logic job in a SQL Server instance within a web application. When something goes wrong all of them queue a message in a specific table (let's say 'warnings') keeping track of the error severity and issue description. I want the web application using the stored procs to be able to query the message table at the end of the run but getting a list of the proper message only, i.e. the message created during the specific session or that specific connection: so I am in doubt if
have the web application send to the db a guid to INSERT as column value in the message records (but somehow I have to keep track of it in several stored procs running at the page level, so I need something "global")
OR
if I can use some id related to the connection opened by the application - and this would be definitely more sane. Something like (this is pseudo code):
SELECT #sessionid = sessionid FROM sys.something where this = that
Have some hints?
Thanks a lot for your ideas
To retrieve your current SessionId in SQL Server you can simply execute the following:
select ##SPID
See:
http://msdn.microsoft.com/en-us/library/ms189535.aspx

Resources