Thursday, February 10, 2011

DataBinder.Eval versus Explicit Casting


http://unboxedsolutions.com/sean/archive/2005/03/06/455.aspx


DataBinder.Eval versus Explicit Casting

As a regular DataBinder.Eval() user, now I feel a little bit guilty after reading this KB article, and I'm curious how many ASP.NET developers use explicit casting on a regular basis. Drop me a line and let me know.
Let's say you are binding to a DataSet. This...
<%# ((System.Data.DataRowView)Container.DataItem)["au_id"] %>
...is significantly faster than this...
<%# DataBinder.Eval(Container.DataItem, "au_id") %>

Wednesday, February 9, 2011

Working with IntelliSense in SQL Server 2008 Management Studio


Content of this post belongs to 

Working with IntelliSense in SQL Server 2008 Management Studio

IntelliSense in SQL Server 2008 Management Studio provides easy access to language elements when writing T-SQL queries. Knowing the basics can simplify coding in a big way.

While writing Transact-SQL queries in SQL Server 2008 Management Studio, you may have noticed some changes like detail windows and drop-down lists that appear as you type code.
These occur because of IntelliSense, an auto-completion system supported in the most recent version of Management Studio that provides easy access to language elements as you write your queries.

Specifically, IntelliSense displays parameter definitions, completes object names, provides identifier declarations, matches delimiter pairs, and marks incorrect syntax. The better you understand this functionality, the more productive your coding experience will be.
Displaying parameter information
IntelliSense shows parameter information for functions and stored procedures. The information is displayed in a detail window and includes the name and type of each parameter.

For example, Figure 1 demonstrates the parameter information for the DATEADD function. Notice the information includes the data type of the returned value.

Figure 1: Displaying the parameter information for the DATEADD function

Parameter information is displayed automatically under the following conditions:

  • For functions, the information is displayed as soon as you type the opening parenthesis that follows the function.
  • For stored procedures, the information is displayed as soon as you type the space after the stored procedure name.

When the detail window is first displayed, the first parameter is bold. After you type that parameter value, the second parameter turns bold, and so on. For example, in Figure 1 the cursor is at the second parameter value and the second value is bold in the detail window.
The detail window closes after you type the ending parenthesis or you move the cursor to another part of the code. If you need to redisplay the detail window, move the cursor to the appropriate location (after the function's opening parenthesis or after the stored procedure's first space), and press CTRL+SHIFT+SPACE. To close the detail window, press ESC.
Completing object names
When you start typing the name of an object – like a variable, schema, table, column or function – IntelliSense displays a drop-down list with possible options for that position in the code. For instance, if you type after the first space that follows the FROM keyword, you get a list of objects such as databases and schemas. If you specify a schema name, followed by a period, you're presented with a list of tables and views.
The more letters you type in the object name, the closer you will match the name of the object. For example, if you select the Sales schema and then type Sal, the highlight moves to the SalesOrderDetail table, the first table in the drop-down list that begins with Sal. You can then use the arrow keys to move the highlight to the desired table, as shown in Figure 2 (in this case, SalesOrderHeader). Once the table is highlighted, press ENTER and the table name is added to your code.

Figure 2: Completing a table name for the Sales schema

Notice that a detail window also appears next to the highlighted table name. The detail window displays the identifier declaration (described in the next section). If the drop-down list is not displayed, move the cursor to the appropriate location, and then press ALT+RIGHT ARROW. To close the drop-down list without selecting an object, press ESC.
Viewing identifier declarations It can be useful to view details about different types of objects in your T-SQL code.
If you move your cursor over an object like a table or function, IntelliSense automatically provides details about that particular object. For example, if you move your cursor over a table name, the detail window displays the object type and the table's fully qualified name, as shown in Figure 3.
Figure 3: Viewing the fully-qualified name of the SalesOrderHeader table

The information IntelliSense displays depends on the object type. If a cursor is over a function name, a detail window displays the type of function, parameter information and the data type of the return value. On the other hand, the detail window for a column includes information like the object type, data type and whether null values are permitted.
Matching delimiter pairs
IntelliSense is also capable of matching delimiter pairs within your T-SQL. For the database engine, delimiter pairs include parentheses as well as BEGIN…END, BEGIN TRY…END TRY, and BEGIN CATCH…END CATCH code blocks. IntelliSense matches a pair by highlighting the opening and closing parentheses or key words.
Figure 4 shows a BEGIN…END block, with the keywords highlighted.
Figure 4: Matching a BEGIN…END pair

IntelliSense automatically highlights the delimiter pair when you finish typing the second delimiter. For example, in the above figure IntelliSense highlighted the BEGIN and END keywords as soon as I finished typing END.
Matching delimiter pairs is particularly helpful when there are multiple code blocks embedded in each other. The highlighting remains until you move your cursor. If you want to re-highlight a pair, you must delete and then re-type one of the letters (or parenthesis) in that pair. You can also use the CTRL+] shortcut to jump from one of the delimiters in a pair to the other.
Verifying incorrect syntax
IntelliSense automatically marks any errors in the syntax so you can see immediately whether there are any problems with your code. Any syntax that is incorrect is displayed with a squiggly red underline, as shown in Figure 5.
Figure 5: Viewing incorrect syntax in a SELECT Statement

Although it is handy to know immediately whether your code has errors, it is not always easy to tell from the red underlines where the problem might be. In the case of the statement shown in Figure 5, the problem is that the table name is incorrect (it should not end with s). As a result, all the column names are treated as errors, even though they are correct. You may have to dig sometimes to figure out what the actual problem is, particularly for more complex statements.
Modifying IntelliSense options
IntelliSense supports a limited number of options that can be configured.
To access the IntelliSense settings, open the Options dialog box by clicking Options in the Tools menu. Then, to configure the general IntelliSense settings, go to the IntelliSense node, as shown in Figure 6.

Here you can enable IntelliSense, select whether errors are underlined or if function names should be upper case in the object name drop-down list.
Figure 6: Modifying the IntelliSense options (Click to enlarge)

IntelliSense also lets you set statement completion options for all languages, T-SQL, and XML, as shown in Figure 7. In this case, you can determine whether to display the object name drop-down list or parameter information.
Figure 7: Modifying the statement completion options (Click to enlarge)

Although there are only a few options to configure, IntelliSense can still be useful when writing your Transact-SQL code, and while it may take some getting used to, it will be worth the effort in the long term.
Keep in mind, however, that IntelliSense does not support all Transact-SQL syntax, though it does support the statements most commonly used. For more details about supported syntax, see the topic Transact-SQL Syntax Supported by IntelliSense in SQL Server 2008 Books Online.
NOTE: For this article, I provide the shortcut keys for accessing IntelliSense features such as displaying parameter issues. However, Management Studio also includes menu options and toolbar buttons for these features. For details about different ways to access functionality, see the Using IntelliSense section in SQL Server 2008 Books Online.


Related Articles
ABOUT THE AUTHOR:   
Robert Sheldon is a technical consultant and the author of numerous books, articles, and training material related to Microsoft Windows, various relational database management systems, and business intelligence design and implementation. His books include Beginning MySQL (part of the Wrox Programmer-to-Programmer series), SQL: A Beginner's Guide(based on the SQL:1999 standard), MCSE Training Kit: Designing Highly Available Web Solutions with Microsoft Windows 2000 Server Technologies, and MCSE Training Kit: Microsoft SQL Server 2000 Database Design and Implementation. You can find more information at http://www.rhsheldon.com.

Thursday, February 3, 2011

sms global user

WAP Push
http://www.smsglobal.com/http-api.php?action=sendsms&msgtype=wappush&user=USERNAME&password=PASSWORD&from=FROMNUMBER&to=TONUMBER&url=URL&subject=SUBJECT
SSL is available via the same URL but https://
https://www.smsglobal.com/http-api.php?action=sendsms&msgtype=wappush&user=USERNAME&password=PASSWORD&from=FROMNUMBER&to=TONUMBER&url=URL&subject=SUBJECT
This section describes how to send requests from the Client Application (Client) to the Messaging Exchange (MeX) and the possible responses to such requests.
The Client issues a HTTP GET or POST request to the MeX using a specific URL. The MeX issues back a response, which completes the transaction. Please note that the MeX response can either be an HTTP error code or a HTTP OK (200) in which case the returned response body will contain further information.
The Client supplies a number of parameters to the MeX in the request as described below.
PARAMETERDESCRIPTIONPRESENCE
ACTIONAction taken. Eg: sendsmsMandatory
MSGTYPESet to "wappush". Sends WAP link to the recipient's phoneMandatory
USERNAMEUsername for MP accountMandatory
PASSWORDPassword for MP accountMandatory
FROMNUMBERSource address (sender)Mandatory
TONUMBERDestination address (recipient) MSISDN should be on international format starting with country code. Example: 61409317436 (Do not use + before the country code!)Mandatory
URLThe URL to be pushed (must be URL-encoded)Mandatory
SUBJECTThe subject of the message (must be URL-encoded)Mandatory
EXAMPLE - SENDING VCARD
Username: USERNAME
Password: SECRET
To Address: +61 409317436
Subject: SMSGlobal's website
URL: http://www.smsglobal.com
http://www.smsglobal.com/http-api.php?action=ACTION&user=USERNAME& password=SECRET&from=FROMNUMBER&to=61409317436&subject=SMSGlobal's+website &url=http%3a%2f%2fwww.smsglobal.com
RESPONSES
Responses from the Messaging Exchange (MeX) are encoded in a HTTP response, which contain an status code according to the SMPP specification which is either 0 (OK) or an error code.
Response body includes one or, optionally, two lines:
  1. Contains the status code, 0 for success or otherwise a numeric value other than 0 indicating what error occurred.
  2. If present, contains a text describing the error that occurred.
SUCCESS / FAILURE RESPONSES
Example: Response indicating success
  0
  OK
Example: Response indicating failure
  ADD DETAILS
  Recipient (TONUMBER) is missing
Returns Status code If Status = 0 then returns OK:0 sent queued message ID; SMSGlobalID: MessageID (to use in Statussms)
If Status <> 0 then returns WARNING: Status code
Incoming SMS - Receive replies on your webserverIncoming SMS will be delivered to the URL specified in the preferences page once you have logged into your account. Check under the "Incoming SMS Settings" section.

The arguments are:
TO (which number the message was sent to)
FROM (the sender's MSISDN)
MSG (the contents of the message)
USERFIELD (the same INTERNAL ID submitted when sending the SMS that the incoming SMS is a reply to)
DATE (the date and time the message was received by SMSGlobal's servers)
e.g. if a phone is turned off, you will receive a DLR status with 107 Absent subscriber with the DONEDATE at the initial attempt to send the message, then when the phone is turned back on, you will receive another DLR report with the same message id with an updated status of DELIVRD, and the DONEDATE of the time the message was delivered when the phone was turned on.
So e.g. a url would be http://www.yourserver.com/receivedlr.php?to=TONUMBER&from=FROMNUMBER&msg=TEXT&userfield=YOURINTERNALID&date=DATETIME
Please respond with "OK" to complete delivery of the message. If SMSGlobal receives no response, we assume your server is down and continue to attempt to send the message to you.
Balancesms - Check MeX balance for the user account USERNAMEhttp://www.smsglobal.com/http-api.php?action=balancesms&user=USERNAME&password=PASSWORD

Possible error codes through API
Error code valueDescription
SND_TIMEOUT = "400"Send message timed-out
SND_TEMP_DISABLED = "401"System temporary disabled
SND_NO_RESPONSE = "402"No response from SMSGlobal SMSC
SND_BIND_ERROR = "13"ESME_RBINDFAIL - Can not Bind to MeX
SND_SMPP_ERROR = "8"ESME_RSYSERR - System Error
SND_SMPP_ERROR = "1"ESME_RINVMSGLEN Message Length is invalid
SND_SMPP_ERROR = "2"ESME_RINVCMDLEN Command Length is invalid
SND_SMPP_ERROR = "3"ESME_RINVCMDID Invalid Command ID
SND_SMPP_ERROR = "4"ESME_RINVBNDSTS Incorrect BIND
SND_SMPP_ERROR = "5"ESME_RALYBND ESME Already in Bound State
SND_SMPP_ERROR = "10"ESME_RINVSRCADR Invalid Source Address
SND_SMPP_ERROR = "11"ESME_RINVDSTADR Invalid Dest Addr
SND_SMPP_ERROR = "12"ESME_RINVMSGID Message ID is invalid
SND_SMPP_ERROR = "13"ESME_RBINDFAIL Bind Failed
SND_SMPP_ERROR = "14"ESME_RINVPASWD Invalid Password
SND_SMPP_ERROR = "69"ESME_RSUBMITFAIL Submit SM failed
SND_SMPP_ERROR = "88"ESME_RTHROTTLED Exceeded allowed message limits
SND_SMPP_ERROR = "102"Destination not covered or Unknown prefix