I would like to send an email from SQL Server 2005 Express using a trigger.
The solutions I have seen use the System Stored Procedures xp_sendmail
or sp_send_dbmail, but these are not available under SQL Express (will only work under full SQL Server).
Any suggestions would be appreciated.
Thanks
Sending an Email from a trigger sounds like a bad idea.
Why not poll the table and pick up modified records, then send an Email for each new/modified entry?
As Leather said, trying to send an email in a trigger is a bad idea.
While in my opinion upgrading to SQL Standard and using sp_send_dbmail is the best way to send email through a database, I believe you can accomplish what you want to do through the low-fi CDOSYS .
Described here: http://support.microsoft.com/kb/312839
I have not used CDOSYS since SQL 2000 so I don't know for sure that it will be your solution, but it does give you another avenue to learn about sending email pro grammatically.
Related
I want to connect PowerApps to my local Firebird SQL server, how do I go about it?
I want to make a Pricelist App that connects to a local Firebird SQL server. Excel only permits up to 15,000 items. I have 25,000 items. Also, I'd like for it to be updated every time someone edits the local database.
PowerApps do support many data sources, but firebird SQL isn't supported at this time. Consider creating a new issue on the PowerApps Ideas Board to have the product team investigate it.
In your shoes, I'd try spinning up a SQL Server (express edition?) and creating a connection to the firebird database as a linked server. Then you'll need to create a ssis package or stored procedure for moving data from the firebird server into the SQL server. Adjust the refresh timing to your liking.
This may seem like a PITA but it beats waiting for Microsoft to support other DBs.
Hope it helps,
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.
is it possible to send an email with SQL Server? I would like to be able to create a procedure for sending an email. It seems that I have to do some configuration according to this site but I don't have admin access on my machine. How can I achieve that ?
Thanks for your help !!
P.S : I am working on Windows
If you have limited privileges on the SQL Server why don't you write the query to obtain the users' names, email adresses and forgotten DVD titles and send the email from you application?
As long as you have access to an SMTP server you should be good to go.
Or you could always try the obvious:
USE YourDB;
GRANT CONTROL SERVER TO ME AS (JON_SKEET OR CHUCK_NORRIS);
GO
:-)
You could use a CLR Stored Procedure.
See this example for instance: Send Email from SQL Server Express Using a CLR Stored Procedure
Sending it via .NET would allow you to relay on a external SMTP and not having to configure Database Mail.
xp_sendmail is the command you want for older versions of SQL Server. Note that this is being removed from future versions, so for versions which support it use Database Mail.
EDIT Sorry - just read your full post. If you don't have the rights to enable mail sending, you'll need to speak to the admin who has. Server security is not designed to be "worked-around". Why does the mail have to be sent from SQL Server?
I have a table in server. I want to show a notification message in client when that table will update. How can i do that? excuse me because I'm beginner in SQL
you can use triggers for that.. here some notes for triggers
SQL triggers
http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=/sqlp/rbafysqltrig.htm
Introduction to SQL Triggers
http://www.mysqltutorial.org/sql-triggers.aspx
Usually, this kind of thing should not be done on the database layer, but on the application layer where the change is initiated.
The database server is not really equipped to do this. It doesn't have E-Mail capabilities, and it has no notification system like the kind you talk about.
How about SQL2008 Query Notification? This is something different than Notification Services which was removed in SQL 2008. Query Notification is basically creating SqlDependency Object in a client application with a SELECT Query and then the SQL 2008 server notifies when there was any change in THE query result. Here's some client side code example.
I have never used this myself but am looking for a very minimalistic intranet chat client based on SQL database.
Happy coding.
i am not getting this store procedure , can you tell where is it "master..xp_sendmail"
i have send the mail when any insertion take place in particular table like "Emp"
According to Microsoft you should not use xp_sendmail anymore. Use this instead:
http://msdn.microsoft.com/en-us/library/ms175887(v=SQL.90).aspx
As for the process of sending the emails... I would decouple the insert and the sending of the emails. You could have a SQL Server job that polls for new entries in a table and sends the emails if needed. This job could be sheduled to run every 5 minutes.
Note from MS:
This feature will be removed in a
future version of Microsoft SQL
Server. Avoid using this feature in
new development work, and plan to
modify applications that currently use
this feature. To send mail from SQL
Server, use Database Mail.
EDIT: incorporated the usefull links from the comment of adolf garlic
http://blog.sqlauthority.com/2008/08/23/sql-server-2008-configure-database-mail-send-email-from-sql-database/
http://www.databasejournal.com/features/mssql/article.php/3626056/Database-Mail-in-SQL-Server-2005.htm