How to send email using sqlserver
This is from CodeProject:http://www.codeproject.com/Articles/846204/How-To-Send-Mail-Using-SQL-Server-Part Introduction There are three parts for this tutorial: Configure email profile and send test email using SQL Server Select and send d
This is from CodeProject:http://www.codeproject.com/Articles/846204/How-To-Send-Mail-Using-SQL-Server-Part
Introduction
There are three parts for this tutorial:
- Configure email profile and send test email using SQL Server
- Select and send data in mail
- Schedule daily mail from SQL Server
Step 1
Log in to SQL Server 2008 with a correct user name and password.
Step 2
Expand the Management tab, then select SQL Server Logs, then right-click on Database Mail, then select Configure Database Mail.
Step 3
The following window appears:
Click Next.
Step 4
Select the Set up Database Mail by performing the following tasks: radio button.
Step 5
Click Next, then a confirmation box appears; click OK on that.
Step 6
When you click OK, then write the profile name description and click on Add.
Step 7
Then, a new window appears where you provide your profile name and configure Outgoing Mail Server(SMTP) then click Basic authentication and provide your email id and password then click OK.
Step 8
Then in the new window, it will show your profile, check that and click Next.
Step 9
Then in the new window, the Configure System Parameters description is shown.
Step 10
Click Next. It will show a confirmation about your profile; click Finish.
Step 11
Now the email service has been configured, click Close.
Step 12
Send a test email by right-clicking on database mail and click Send Test E-Mail.
Step 13
Provide the Test Email Id and click On Send Test E-Mail. Then check your mail to see if you got the mail. Enjoy!!
Note
After the Account and the Profile are created successfully, we need to configure the Database Mail. To configure it, we need to enable the Database Mail XPs parameter using the
sp_configure
Stored Procedure, as shown here:
Collapse |
Copy Code
sp_CONFIGURE <span>'</span><span>show advanced'</span>, <span>1</span> <span>GO</span> <span>RECONFIGURE</span> <span>GO</span> sp_CONFIGURE <span>'</span><span>Database Mail XPs'</span>, <span>1</span> <span>GO</span> <span>RECONFIGURE</span> <span>GO</span>
Output Message
The Configuration option "show advanced options" changed from 0 to 1. Run the
RECONFIGURE
statement to install.
The configuration option "Database Mail XPs" changed from 1 to 1. Run the
RECONFIGURE
statement to install.
Use the following query to send mail using query:
Send Mail Query
USE msdb;--Must Use msdb database, otherwise you will get error.
Collapse |
Copy Code
<span>GO</span> <span>EXEC</span> sp_send_dbmail @profile_name=<span>'</span><span>MyTestMail'</span>, @recipients=<span>'</span><span>manishki@live.com'</span>, @subject=<span>'</span><span>My Test Mail Service.'</span>, @body=<span>'</span><span>Database Mail Received Successfully.'</span>
This is the body of this message.
Note
If you are using a database other than msdb, then use a stored procedure like
msdb.dbo.sp_send_dbmail
. The log can be checked in sysmail_log
table as shown below:
Collapse |
Copy Code
<span>SELECT</span> * <span>FROM</span> sysmail_mailitems <span>GO</span> <span>SELECT</span> * <span>FROM</span> sysmail_log <span>GO</span> <span>select</span> * <span>from</span> sysmail_log

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

匯入步驟如下:將 MDF 檔案複製到 SQL Server 的資料目錄(通常為 C:\Program Files\Microsoft SQL Server\MSSQL\DATA)。在 SQL Server Management Studio(SSMS)中,開啟資料庫並選擇「附加」。點選“新增”按鈕,選擇 MDF 檔案。確認資料庫名稱,點選確定按鈕即可。

對於 SQL Server 資料庫中已存在同名對象,需要採取下列步驟:確認物件類型(表格、檢視、預存程序)。如果物件為空,可使用 IF NOT EXISTS 跳過建立。如果物件有數據,使用不同名稱或修改結構。使用 DROP 刪除現有物件(謹慎操作,建議備份)。檢查架構更改,確保沒有引用刪除或重新命名的物件。

若要查看 SQL Server 連接埠號碼:開啟 SSMS,連線到伺服器。在物件資源管理器中找到伺服器名稱,右鍵單擊它,然後選擇“屬性”。在「連線」標籤中,查看「TCP 連接埠」欄位。

若誤刪 SQL Server 資料庫,可採取下列步驟還原:停止資料庫活動;備份日誌檔案;檢查資料庫日誌;復原選項:從備份還原;從交易日誌還原;使用 DBCC CHECKDB;使用第三方工具。請定期備份資料庫並啟用交易日誌以防止資料遺失。

SQL Server 資料庫檔案通常儲存在下列預設位置:Windows: C:\Program Files\Microsoft SQL Server\MSSQL\DATALinux: /var/opt/mssql/data可透過修改資料庫檔案路徑設定來自訂資料庫檔案位置。

當 SQL Server 服務無法啟動時,可採取下列步驟解決:檢查錯誤日誌以確定根本原因。確保服務帳戶具有啟動服務的權限。檢查依賴項服務是否正在執行。禁用防毒軟體。修復 SQL Server 安裝。如果修復不起作用,重新安裝 SQL Server。

問題發現這次使用的是SqlServer資料庫,之前並沒有使用過,但是問題不大,我按照需求文檔的步驟連接好SqlServer之後,啟動SpringBoot項目,發現了一個報錯,如下:剛開始我以為是SqlServer連接問題呢,於是便去查看資料庫,發現資料庫一切正常,我首先第一時間問了我的同事,他們是否有這樣的問題,發現他們並沒有,於是我便開始了我最拿手的環節,面向百度程式設計.開始解決具體報錯資訊是這樣,於是我便開始了百度報錯:ERRORc.a.d.p.DruidDataSource$CreateCo

如果 SQL Server 安裝失敗,可透過下列步驟清理:解除安裝 SQL Server刪除註冊表項刪除檔案和資料夾重新啟動計算機
