Tuesday, 21 June 2016

Difference between LINQ to SQL and Entity Framework:

Difference between LINQ to SQL and Entity Framework:

LINQ to SQL:
  • It only works with SQL Server Database.
  • It generates a .dbml to maintain the relation
  • It has not support for complex type.
  • It cannot generate database from model.
  • It allows only one to one mapping between the entity classes and the relational tables /views.
  • It allows you to query data using DataContext.
  • It provides a tightly coupled approach.
  • It can be used for rapid application development only with SQL Server.
Entity Framework
  • It can works with various databases like Oracle, DB2, MYSQL, SQL Server etc.
  • It generates an .edmx files initially. The relation is maintained using 3 different files .csdl, .msl and .ssdl
  • It has support for complex type.
  • It can generate database from model.
  • It allows one-to-one, one-to-many & many-to-many mappings between the Entity classes and the relational tables /views
  • It allows you to query data using EntitySQL, ObjectContext, DbContext.
  • It provides a loosely coupled approach. Since its code first approach allow you to use Dependency Injection pattern which make it loosely coupled .
  • It can be used for rapid application development with RDBMS like SQL Server, Oracle, DB2 and MySQL etc.

Wednesday, 12 August 2015

How To Send Mail Using SQL Server

Create procedure as.....

ALTER PROCEDURE [dbo].[usp_SendTextEmail]  @ServerAddr nvarchar(128),
@From nvarchar(128),
@To nvarchar(1024),
@Subject nvarchar(256),
@Bodytext nvarchar(max) = 'This is a test text email from MS SQL server, do not reply.',
@User nvarchar(128) = '',
@Password nvarchar(128) = '',
@SSLConnection int = 0,
@ServerPort int = 25

AS

DECLARE @hr int
DECLARE @oSmtp int
DECLARE @result int
DECLARE @description nvarchar(255)

EXEC @hr = sp_OACreate 'EASendMailObj.Mail',@oSmtp OUT 
If @hr <> 0 
BEGIN
    PRINT 'Please make sure you have EASendMail Component installed!'
    EXEC @hr = sp_OAGetErrorInfo @oSmtp, NULL, @description OUT
    IF @hr = 0
    BEGIN
        PRINT @description
    END
    RETURN
End

EXEC @hr = sp_OASetProperty @oSmtp, 'LicenseCode', 'TryIt'
EXEC @hr = sp_OASetProperty @oSmtp, 'ServerAddr', @ServerAddr
EXEC @hr = sp_OASetProperty @oSmtp, 'ServerPort', @ServerPort

EXEC @hr = sp_OASetProperty @oSmtp, 'UserName', @User
EXEC @hr = sp_OASetProperty @oSmtp, 'Password', @Password

EXEC @hr = sp_OASetProperty @oSmtp, 'FromAddr', @From

EXEC @hr = sp_OAMethod @oSmtp, 'AddRecipientEx', NULL,  @To, 0

EXEC @hr = sp_OASetProperty @oSmtp, 'Subject', @Subject 
EXEC @hr = sp_OASetProperty @oSmtp, 'BodyText', @BodyText 


If @SSLConnection > 0 
BEGIN
    EXEC @hr = sp_OAMethod @oSmtp, 'SSL_init', NULL
END

/* you can also add an attachment like this */
/*EXEC @hr = sp_OAMethod @oSmtp, 'AddAttachment', @result OUT, 'd:\test.jpg'*/
/*If @result <> 0 */
/*BEGIN*/
/*   EXEC @hr = sp_OAMethod @oSmtp, 'GetLastErrDescription', @description OUT*/
/*    PRINT 'failed to add attachment with the following error:'*/
/*    PRINT @description*/
/*END*/

PRINT 'Start to send email ...' 

EXEC @hr = sp_OAMethod @oSmtp, 'SendMail', @result OUT  

If @hr <> 0 
BEGIN
    EXEC @hr = sp_OAGetErrorInfo @oSmtp, NULL, @description OUT
    IF @hr = 0
    BEGIN
        PRINT @description
    END
    RETURN
End

If @result <> 0 
BEGIN
    EXEC @hr = sp_OAMethod @oSmtp, 'GetLastErrDescription', @description OUT
    PRINT 'failed to send email with the following error:'
    PRINT @description
END
ELSE 
BEGIN
    PRINT 'Email was sent successfully!'
END

EXEC @hr = sp_OADestroy @oSmtp
============================================================

Call above procedure as .......


/* Gmail SMTP server address */
DECLARE @ServerAddr nvarchar(128)
Set @ServerAddr = 'smtp.gmail.com'

/* Set your Gmail email address */
DECLARE @From nvarchar(128)
Set @From = 'xyz@gmail.com'

DECLARE @To nvarchar(1024)
/*You can input multiple recipients and use comma (,) to separate multiple addresses */
Set @To = 'abc@gmail.com'

DECLARE @Subject nvarchar(256)
Set @Subject = 'simple email from SQL SERVER'

DECLARE @Bodytext nvarchar(512)
Set @BodyText = 'This is a test text email from MS SQL server, do not reply.'

/* Gmail user authentication should use your 
 Gmail email address as the user name. 
For example: your email is "gmailid@gmail.com", then the user should be "gmailid@gmail.com" */
DECLARE @User nvarchar(128)
Set @User = 'xyz@gmail.com'

DECLARE @Password nvarchar(128)
Set @Password = 'pwd#123'

/* Enable SSL/TLS */
DECLARE @SSLConnection int
Set @SSLConnection = 1

/* If you want to use TLS, please set it to 25 or 587 */
DECLARE @ServerPort int
Set @ServerPort = 587

PRINT 'start to send email ...'


exec usp_SendTextEmail @ServerAddr, @From, @To, @Subject, @BodyText, @User, @Password, @SSLConnection, @ServerPort

Monday, 13 April 2015

What is the difference between jquery.size() and jquery.length

jquery.size() and jquery.length both returns the number of element found in the object. But, jquery.length is faster than jquery.size() because size() is a method but length is a property .

jQuery .size() method returns number of element in the object. But it is not preferred to use the size()method as jQuery provide .length property and which does the same thing. But the .length property is preferred because it does not have the overhead of a function call. 

Difference Between Constant and ReadOnly and Static

Constant

Constant fields or local variables must be assigned a value at the time of declaration and after that they cannot be modified. By default constant are static, hence you cannot define a constant type as static.

ReadOnly

A readonly field can be initialized either at the time of declaration or with in the constructor of same class. Therefore, readonly fields can be used for run-time constants.

Static

The static keyword is used to specify a static member, which means static members are common to all the objects and they do not tied to a specific object.

Saturday, 4 April 2015

The maximum string content length quota (8192) has been exceeded while reading XML data.

Unhandled Exception: System.ServiceModel.CommunicationException: Error in deserializing body of reply message for operation ‘GetData’. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader.

--------------------------------------------------------------------------------------------------------------------------
Change in to the web.config file
--------------------------------------------------------------------------------------------------------------------------
<bindings>
      <basicHttpBinding>
        <binding>
          <readerQuotas maxStringContentLength=”2147483647″/>
        </binding>
      </basicHttpBinding>
</bindings>

Wednesday, 1 April 2015

Multiple Inheritance in c#


C# does not support multiple inheritance. However, you can use interfaces to implement multiple inheritance. The following program demonstrates this:


namespace MultipleInheritance
{
class A
{
public void disp()
{
Console.WriteLine("disp() method of Class A");
}
}

interface First
{
void mno();
}

interface Second
{
void pqr();
}

class Z:A,First,Second
{
public void mno()
{
console.WriteLine("mno() method is overridden.");
}
public void pqr()
{
console.WriteLine("pqr() method is overridden.");
}

}
}

Friday, 20 March 2015

Retrieving a Dataset from View State (Visual C#)

If you want dataset on same page and with post back it not destroy use viewstate      

DataSet ds = new DataSet();
            ViewState["ViewStateDateSet"] = ds;//Insert Data Set in View State


            DataSet ds1 = (DataSet)ViewState["ViewStateDateSet"]; // Retrive DataSet from ViewState