Is there an output list of "sp_send_dbmail"? - database

I wanna know output list of sp_send_dbmail, for example when I run sp_send_dbmail and the output is 0 it was successful, also if the output is 20, it did not find the recipients.
So I want to know if there is a list of output for sp_send_dbmail

According to MS Documentation, sp_send_dbmail() returns 0 if the process of sending mails could be started without error. This means, mails have been set in the database mail queue, and for every mail the mailitem_id for the message is returned in the result set.
Any return value other than 0 means error. The precise error code of the failed statement can be seen in ##ERROR.
After using sp_send_dbmail(), the mail is sent asynchronously and it still can fail for many reasons. So if sp_send_dbmail() returns 0, it does not mean final success.
You might look in msdb.dbo.sysmail_faileditems as in the case of error, the mails would be there (http://www.sqlservercentral.com/Forums/Topic1030781-23-1.aspx).

Related

Gmail api messages/list Q after:{timestamp} doe not work properly

Good time!
I'm trying to get the list of message and to filter them I use Q after:{timestamp}
I do the following query
After getting the message id I do a query to get the details of the message:
As you can see timestamp in the query and internalDate of the message are the same.
When I increment timestamp value to 1559717792 and do a query I get the same result:
In my view, the result should be empty because the internalDate less than 1559717792. Is it an issue or is it my mistake?
Thank you!
Gmail API uses the same search syntax as web interface and it's documented here:
https://support.google.com/mail/answer/7190
Specifically it never says "after:<epochSeconds>" works but it only gives an option for a formatted date "after:YYYY/MM/DD". Emperically the <epochSeconds> does seem to work, but it's not documented (so beware that it's not guaranteed to be supported and may break at any time) and also it seems that there may be some rounding issues within the same second (so you may have to add or remove a second to always get the results you want if you need that level of accuracy).

Equivalent java code for IMAP command

We are using Godaddy email server. We are trying fetch emails using IMAP protocol . Following are my sample IMAP commands
a select inbox
a UID SEARCH FROM "user1#server.com"
Results are getting fine for above commands something like below
* SEARCH 501 505 342 229 191
a OK SEARCH done.
If I write equivalent Java code for above commands , I'm getting empty results. Following is Java code.
IMAPFolder inbox = store.getFolder("INBOX");
SearchTerm fromTerm = new FromTerm(new InternetAddress("user1#server.com"));
Message[] messages = inbox.search(fromTerm);
The generated IMAP command for above Java code is
a SEARCH FROM user1#server.com ALL
but UID is missing in above java generated command so I'm getting empty results . How to include UID while using with Java
Thanks
The UID tag in the SEARCH command indicates that UIDs should be returned instead of message sequence numbers. Since JavaMail primarily works with message sequence numbers, it doesn't support UID SEARCH. It uses the returned message sequence numbers to map to the corresponding Message objects. Nonetheless, the messages should be "found" independently of whether their UIDs or their message sequence numbers are returned. If the server is only returning results for UID SEARCH, the server is broken and you should report this server bug to GoDaddy.

SQL Server --- using raiserror without status accident

I wanted to user RAISERROR in my SQL-Server codes but I noticed that some status code have interruption with built-in SQL Error statuses...
for example status code "1" is used for "Devide By Zero Error", And I dont wanna use it any more...
now I want to see what status codes are safe to use withour interruption ?
If you want to use your own msgid use a value of greater then 50000. The values below 50000 are reserved for built in messages. To see the list of existing messages you can do a 'select * from sys.messages'. 50000 is used when a value for msgid is not provided.

Access database in Physionet's ptbdb by Matlab

I set up the system first by
[old_path]=which('rdsamp');if(~isempty(old_path)) rmpath(old_path(1:end-8)); end
wfdb_url='http://physionet.org/physiotools/matlab/wfdb-app-matlab/wfdb-app-toolbox-0-9-3.zip';
[filestr,status] = urlwrite(wfdb_url,'wfdb-app-toolbox-0-9-3.zip');
unzip('wfdb-app-toolbox-0-9-3.zip');
cd mcode
addpath(pwd);savepath
I am trying to read databases from Physionet.
I have successfully reached one database mitdb by
[tm,sig]=rdsamp('mitdb/100',1)
but I want to reach the database ptbdb unsuccessfully by
[tm,sig]=rdsamp('ptbdb/100',1)
and get the error
Warning: Could not get signal information. Attempting to read signal without buffering.
> In rdsamp at 107
Error: Cannot convert to double:
init: can't open header for record ptbdb/100
Error using rdsamp (line 145)
Java exception occurred:
java.lang.NumberFormatException: Cannot convert
at org.physionet.wfdb.Wfdbexec.execToDoubleArray(Unknown Source)
The first error message refers to these lines in rdsamp.m:
if(isempty(N))
[siginfo,~]=wfdbdesc(recordName);
if(~isempty(siginfo))
N=siginfo(1).LengthSamples;
else
warning('Could not get signal information. Attempting to read signal without buffering.')
end
end
This line if(~isempty(siginfo)) is false means that the siginfo is empty that is there is no signal. Why? No access to the database, I think.
I think other errors follow from it.
So the error must follow from this line
[siginfo,~]=wfdbdesc(recordName);
What does the snake mean here in the brackets?
How can you get data from ptbdb by Matlab?
So
Does this error mean that the connection cannot be established to the database?
or
that there does not exists such data in the database?
It would be very nice to know how you can check if you have connection to the database like in Postrgres. It would be much easier to debug.
If you run physionetdb("ptdb",1) it will download the files to your computer. You will then be able to see the available records in the <current-dir>/ptdb/
Source: physionetdb function documentation. You are interested in the DoBatchDownload parameter.
After downloading it, I believe every command from the toolbox will check if you have the files locally before fetching from the server (as long as you give the function the correct path to the local files).
The problem is that the data unit "100" does not exist in the database ptbdb.
I run finally successfully after waiting 35 minutes with 100Mb cable broadband:
db_list = physionetdb('ptbdb')
and get not complete data finally to the patient 54 - there should be 294 patients.
'ptbdb/patient001/s0014lre' 'ptbdb/patient001/s0014lre' ... cut ...
The main developer, Ikaro's' answer helped me to wait so long:
The WFDB Toolbox connects to PhysioNet's file server. The databases
accessible through the WFDB Toolbox are not SQL database, they consist
of flat files. The error message that you are getting regarding the
ptdb/100 database is because you are attempting to get a record that
does not exist on the database.
For more information on a particular database or record in PhysioNet
please type:
help physionetdb
and
physionetdb('ptdb')
This flat file system is really a bottle neck in the system.
It would be a good time to change to SQL.

PRINT statement in T-SQL

Why does the PRINT statement in T-SQL seem to only sometimes work? What are the constraints on using it? It seems sometimes if a result set is generated, it becomes a null function, I assumed to prevent corrupting the resultset, but could it's output not go out in another result set, such as the row count?
So, if you have a statement something like the following, you're saying that you get no 'print' result?
select * from sysobjects
PRINT 'Just selected * from sysobjects'
If you're using SQL Query Analyzer, you'll see that there are two tabs down at the bottom, one of which is "Messages" and that's where the 'print' statements will show up.
If you're concerned about the timing of seeing the print statements, you may want to try using something like
raiserror ('My Print Statement', 10,1) with nowait
This will give you the message immediately as the statement is reached, rather than buffering the output, as the Query Analyzer will do under most conditions.
The Print statement in TSQL is a misunderstood creature, probably because of its name. It actually sends a message to the error/message-handling mechanism that then transfers it to the calling application. PRINT is pretty dumb. You can only send 8000 characters (4000 unicode chars). You can send a literal string, a string variable (varchar or char) or a string expression. If you use RAISERROR, then you are limited to a string of just 2,044 characters. However, it is much easier to use it to send information to the calling application since it calls a formatting function similar to the old printf in the standard C library. RAISERROR can also specify an error number, a severity, and a state code in addition to the text message, and it can also be used to return user-defined messages created using the sp_addmessage system stored procedure. You can also force the messages to be logged.
Your error-handling routines won’t be any good for receiving messages, despite messages and errors being so similar. The technique varies, of course, according to the actual way you connect to the database (OLBC, OLEDB etc). In order to receive and deal with messages from the SQL Server Database Engine, when you’re using System.Data.SQLClient, you’ll need to create a SqlInfoMessageEventHandler delegate, identifying the method that handles the event, to listen for the InfoMessage event on the SqlConnection class. You’ll find that message-context information such as severity and state are passed as arguments to the callback, because from the system perspective, these messages are just like errors.
It is always a good idea to have a way of getting these messages in your application, even if you are just spooling to a file, because there is always going to be a use for them when you are trying to chase a really obscure problem. However, I can’t think I’d want the end users to ever see them unless you can reserve an informational level that displays stuff in the application.
Query Analyzer buffers messages. The PRINT and RAISERROR statements both use this buffer, but the RAISERROR statement has a WITH NOWAIT option. To print a message immediately use the following:
RAISERROR ('Your message', 0, 1) WITH NOWAIT
RAISERROR will only display 400 characters of your message and uses a syntax similar to the C printf function for formatting text.
Please note that the use of RAISERROR with the WITH NOWAIT option will flush the message buffer, so all previously buffered information will be output also.
I recently ran into this, and it ended up being because I had a convert statement on a null variable. Since that was causing errors, the entire print statement was rendering as null, and not printing at all.
Example - This will fail:
declare #myID int=null
print 'First Statement: ' + convert(varchar(4), #myID)
Example - This will print:
declare #myID int=null
print 'Second Statement: ' + coalesce(Convert(varchar(4), #myID),'#myID is null')
For the benefit of anyone else reading this question that really is missing print statements from their output, there actually are cases where the print executes but is not returned to the client. I can't tell you specifically what they are. I can tell you that if you put a go statement immediately before and after any print statement, you will see if it is executed.
Do you have variables that are associated with these print statements been output? if so, I have found that if the variable has no value then the print statement will not be ouput.

Resources