<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Lot about Microsoft database Connectivity , ADO and ADO .net</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/snehadeep/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/snehadeep/feed.xml</link>
    <description>Important information about microsoft database drivers , connectivity , ADO and ADO.NET. Mail me if you have any questions about these topics.</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:50:19 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>SQL Connectivity errors related to SPN and troubleshooting them.</title>
      <link>https://docs.microsoft.com/archive/blogs/snehadeep/sql-connectivity-errors-related-to-spn-and-troubleshooting-them</link>
      <pubDate>Tue, 15 Sep 2009 02:24:04 GMT</pubDate>
      <dc:creator><![CDATA[SnehaDeep]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/snehadeep/2009/09/15/sql-connectivity-errors-related-to-spn-and-troubleshooting-them/</guid>
      <description><![CDATA[You might get the following error when there is any issue related to a SPN in the environment:  1)...]]></description>
      <content:encoded><![CDATA[<p>You might get the following error when there is any issue related to a SPN in the environment:</p>  <p>1) Login failed for user ‘null’</p>  <p>2) Login failed for user ‘’</p>  <p>3) Login failed for user 'NT Authority\Anonymous Logon‘</p>  <p>4) Cannot generate SSPI context</p>  <p>We get these errors when we use windows authentication and there is more than one hop involved in the scenario before passing the authentication to the final destination. For example while browsing a web site which use windows authentication or in case of a linked server.</p>  <p>Let’s take the most common example, when you are browsing a website that is hosted in IIS server and stores information in SQL database. In this case the data is stored in SQL , The web application which is hosted in a separate IIS server talks to this SQL server through windows authentication. Now when a user logs in to the web site on a third box which is also in the same domain as the IIS and SQL server and tries to browse the website, his user account is passed to SQL server via the IIS box in between.</p>  <p>This kind of scenario is called a double hop where the authentication is passed from the originating box (where the user actually opens the website in IE) to the final box (SQL server) in two hops (1. originating box to IIS 2. IIS box to SQL box). In these types of scenarios, Kerberos is a must. Because NTLM cannot delegate authentication in multiple hops. </p>  <p>For Kerberos to work we need proper SPN. If Proper SPNs are not found in active directory, we will encounter the above errors. When we say proper SPN, it means that the SPN should be in proper format, should contain the right information and should not be duplicate.</p>  <p><b><u>Troubleshooting</u></b></p>  <p><b><u>Prerequisites for Kerberos delegation to work.</u></b></p>  <p>1. All computers must be running Windows 2000 or later. </p>  <p>2. All computers must be in the same domain, or domains that trust one another. </p>  <p>3. The domain(s) must be using Active Directory. </p>  <p>4. Kerberos depends on synchronized timing between computers. Out-of-sync computer clocks may cause Kerberos authentication to fail. So all the machines involved in this scenario should have their time synchronised time. </p>  <p><b><u>Active Directory Settings</u></b></p>  <p>1. Domain users who will be connecting through IIS to SQL Server must not have their domain user accounts marked as &quot;Account is sensitive and cannot be delegated&quot; or should have their “Account is trusted for delegation” checked in the Active Directory Users and Computers tool.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/snehadeep/WindowsLiveWriter/SQLConnectivityerrorsrelatedtoSPNandtro_36CB/clip_image002_2.jpg" original-url="https://blogs.msdn.com/blogfiles/snehadeep/WindowsLiveWriter/SQLConnectivityerrorsrelatedtoSPNandtro_36CB/clip_image002_2.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002" border="0" alt="clip_image002" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/snehadeep/WindowsLiveWriter/SQLConnectivityerrorsrelatedtoSPNandtro_36CB/clip_image002_thumb.jpg" original-url="https://blogs.msdn.com/blogfiles/snehadeep/WindowsLiveWriter/SQLConnectivityerrorsrelatedtoSPNandtro_36CB/clip_image002_thumb.jpg" width="206" height="244" /></a></p>  <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/snehadeep/WindowsLiveWriter/SQLConnectivityerrorsrelatedtoSPNandtro_36CB/clip_image003_2.png" original-url="https://blogs.msdn.com/blogfiles/snehadeep/WindowsLiveWriter/SQLConnectivityerrorsrelatedtoSPNandtro_36CB/clip_image003_2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image003" border="0" alt="clip_image003" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/snehadeep/WindowsLiveWriter/SQLConnectivityerrorsrelatedtoSPNandtro_36CB/clip_image003_thumb.png" original-url="https://blogs.msdn.com/blogfiles/snehadeep/WindowsLiveWriter/SQLConnectivityerrorsrelatedtoSPNandtro_36CB/clip_image003_thumb.png" width="205" height="244" /></a></p>  <p>2. The IIS server (the computer that will be delegating) must have &quot;trust computer for delegation&quot; Checked in the Active Directory Users and Computers tool.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/snehadeep/WindowsLiveWriter/SQLConnectivityerrorsrelatedtoSPNandtro_36CB/clip_image005_2.jpg" original-url="https://blogs.msdn.com/blogfiles/snehadeep/WindowsLiveWriter/SQLConnectivityerrorsrelatedtoSPNandtro_36CB/clip_image005_2.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image005" border="0" alt="clip_image005" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/snehadeep/WindowsLiveWriter/SQLConnectivityerrorsrelatedtoSPNandtro_36CB/clip_image005_thumb.jpg" original-url="https://blogs.msdn.com/blogfiles/snehadeep/WindowsLiveWriter/SQLConnectivityerrorsrelatedtoSPNandtro_36CB/clip_image005_thumb.jpg" width="221" height="244" /></a></p>  <p>3. The IWAM account in case of IIS 5 and in case of IIS 6 and higher, the Log on account for the application pool under which the web application is running must also have “Trust this user for delegation” Checked in the Active Directory Users and Computers tool.</p>  <p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/snehadeep/WindowsLiveWriter/SQLConnectivityerrorsrelatedtoSPNandtro_36CB/clip_image007_2.jpg" original-url="https://blogs.msdn.com/blogfiles/snehadeep/WindowsLiveWriter/SQLConnectivityerrorsrelatedtoSPNandtro_36CB/clip_image007_2.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image007" border="0" alt="clip_image007" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/snehadeep/WindowsLiveWriter/SQLConnectivityerrorsrelatedtoSPNandtro_36CB/clip_image007_thumb.jpg" original-url="https://blogs.msdn.com/blogfiles/snehadeep/WindowsLiveWriter/SQLConnectivityerrorsrelatedtoSPNandtro_36CB/clip_image007_thumb.jpg" width="204" height="244" /></a></p>  <p>4. It is necessary to register a &quot;Service Principal Name&quot; (SPN) for SQL Server if SQL Server is not running under the LocalSystem account or a domain admin account. If you are running the SQL service under LocalSystem it will automatically create a SPN for the machine account in active directory and if you are running the SQL service in a domain admin account even in that case it will create its own SPN. But if you are running the SQL account in a different domain account you need to manually create the SPN .</p>  <p>To Create SPN you need to have the domain admin privileges. You can use the SETSPN tools to create or delete SPNs. The SETSPN tool comes with the Windows 2000 Resource Kit Tool.</p>  <p>First run the command “SETSPN –L &lt;domain\SQLService account&gt;” to find out if there is any improper or duplicate SPN(this command does not require domain admin privilages). A valid SQL SPN should be in the format “MSSQLSvc/&lt;FQDN of SQL Server&gt;:&lt;SQL Port&gt;” ex: MSSQLSvc/SQLServer.MyDomain.Com:1433. If you find any improper or duplicate SQL SPN then delete them using the command “SETSPN –D &lt;SPN&gt; &lt; domain\SQLService account &gt;”</p>  <p>(You can also use a tool called Delegconfig to find out if there is a duplicate SPN. You can download this tool from the link <a href="https://www.iis.net/downloads/default.aspx?tabid=34&amp;g=6&amp;i=1434">https://www.iis.net/downloads/default.aspx?tabid=34&amp;g=6&amp;i=1434</a>)</p>  <p>Then add the appropriate SPN with the command “SETSPN –A MSSQLSvc/&lt;FQDN of SQL Server&gt;:&lt;SQL Port&gt; &lt; domain\SQLService account &gt;”</p>  <p>If you are trying to connect to a SQL cluster you need to have two SPNs. One with the port and one without. Preferably you can create 4 SPNs in the following format:</p>  <p>MSSQLSvc/&lt;virtual server name&gt;</p>  <p>MSSQLSvc/&lt;virtual server name&gt;.&lt;rest of FQDN&gt;</p>  <p>MSSQLSvc/&lt;virtual server name&gt;:&lt;port&gt;</p>  <p>MSSQLSvc/&lt;virtual server name&gt;.&lt;rest of FQDN&gt;:&lt;port&gt;</p>  <p>5. For Active Directory to work correctly, DNS must also function correctly. If you are having DNS problems, Kerberos will fail, due to name lookup problems. You can do a ping –a to find out if the IP address and FQDN is being resolved properly.</p>  <p><b><u>Client Computers</u></b></p>  <p>1. Client computers must be running Internet Explorer 5.0 or later </p>  <p>2. In IE, it may be necessary to turn on &quot;Enable Windows Integrated Authentication&quot; in the browser's Advanced Options. </p>  <p>3. Browsers can't be going through a proxy server. If using a proxy must select option in IE to &quot;bypass proxy for local addresses&quot;</p>  <p><b><u>IIS Server</u></b></p>  <p>1. Only Windows Authentication, or Windows and Basic, if necessary (see below), should be enabled on the web site or virtual folder. Digest authentication does not support delegation </p>  <p>2. Specify a trusted connection to SQL Server with &quot;Integrated Security=SSPI&quot; in the connection string. </p>]]></content:encoded>
    </item>
    <item>
      <title>Things to know before developing MS XML applications.</title>
      <link>https://docs.microsoft.com/archive/blogs/snehadeep/things-to-know-before-developing-ms-xml-applications</link>
      <pubDate>Mon, 14 Sep 2009 18:21:06 GMT</pubDate>
      <dc:creator><![CDATA[SnehaDeep]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/snehadeep/2009/09/14/things-to-know-before-developing-ms-xml-applications/</guid>
      <description><![CDATA[XML is a method for putting structured data in a text file . Microsoft XML Core Services...]]></description>
      <content:encoded><![CDATA[<p>XML is a method for putting structured data in a text file . Microsoft XML Core Services (MSXML)&#160; adhere to the XML 1.0 standard.</p>  <p>MSXML can be installed both in replace mode and side by side. For example, starting MSXML4 all the versions are installed side by side. Which means that you system might have multiple versions of MSXML installed.</p>  <p>But When writing code try to use MSXML&#160; v6 as it’s the latest one, If that is not installed on a target machine , MSXML3 is generally the best fallback. Because MSXML 1 and 2 are no longer supported by Microsoft, MSXML 5 is meant only for use in Office products. And MSXML 4 is kill bited.</p>  <p>To know the features of each of the MSXML versions you can visit <a href="https://msdn.microsoft.com/en-us/library/ms753751(VS.85).aspx">https://msdn.microsoft.com/en-us/library/ms753751(VS.85).aspx</a></p>  <p>To find out what are the versions of XML installed in your system , you can use a tool called <a href="https://download.microsoft.com/download/b/b/e/bbe50ceb-1783-4e53-a489-e17dc5aaefb3/xmlversion.exe">Xmlversion.exe</a> or <a href="https://download.microsoft.com/download/b/b/e/bbe50ceb-1783-4e53-a489-e17dc5aaefb3/xmlversion.exe">Xmlversiontext.exe</a>. Yoy can download it from the link&#160; <a href="https://support.microsoft.com/kb/278674/en-us">https://support.microsoft.com/kb/278674/en-us</a> .</p>  <p>To create a XML DOM object we use code like this “Dim xmlDoc As New Msxml2.DOMDocument30”</p>  <p>here&#160; Msxml2.DOMDocument30 is the progID we are using to refer a specific version of XML DOM.</p>  <p>MSXML has multiple versions and the ProgID is different in each on them usually in the form of ProjectName.ClassName.</p>  <p>For example –:</p>  <p>MSXML Version&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; PROGID</p>  <p>1.0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Microsoft.XMLDOM</p>  <p>2.0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Msxml.DOMDocument</p>  <p>3.0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Msxml2.DOMDocument or Msxml2.DOMDocument.3.0 </p>  <p>4.0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Msxml2.DOMDocument.4.0 </p>  <p>6.0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Msxml2.DOMDocument.6.0</p>  <p>Visit <a href="https://support.microsoft.com/?id=305019">https://support.microsoft.com/?id=305019</a> for more details about MSXML&#160; GUID and ProgID.</p>  <p>If you use version independent progID it will refer to the lowest version between MSXML1, MSXML2 and MSXML3. From MSXML4 and later you need to use the version specific ProgID.</p>  <p>Another thing you need to consider is the choise between XMLHTTP and ServerXMLHTTP. XMLHTTP is designed for client applications and relies on URLMon, which is built upon Microsoft Win32 Internet (WinInet). ServerXMLHTTP is designed for server applications and relies on a new HTTP client stack, WinHTTP. </p>  <p>ServerXMLHTTP is recommended for server applications and XMLHTTP is recommended for client applications. For example Use ServerXMLHTTP if you want to use it in a ASP page for example and use XMLHTTP if you want to call it in java script or vb script which is executed in client side. </p>  <p>WinInet limits the number of simultaneous connections that it makes to a single HTTP server using XMLHTTP to 4.But there are no such limits with ServerXMLHTTP. Other than that using ServerXMLHTTP, XML data can be exchanged between local and remote systems as a stream or as XML documents. And because the underlying protocol is HTTP or HTTPS, data can be exchanged between the systems that are behind firewalls. These kind of features maked ServerXMLHTTP suitable for use at server side.</p>  <p>Tracing of ServerXMLHTTP is possible using a tool called Winhttptracecfg. You can download it from <a href="https://support.microsoft.com/kb/307272/en-us">https://support.microsoft.com/kb/307272/en-us</a></p>  <p>If you are writing a .net application try to use System.XML instead of MSXML. As using MSXML with .net application is not supported.</p>  <p><a href="https://support.microsoft.com/kb/290761">https://support.microsoft.com/kb/290761</a></p>]]></content:encoded>
    </item>
    <item>
      <title>Connection leak , its symptoms and troubleshooting .</title>
      <link>https://docs.microsoft.com/archive/blogs/snehadeep/connection-leak-its-symptoms-and-troubleshooting</link>
      <pubDate>Tue, 28 Apr 2009 17:39:00 GMT</pubDate>
      <dc:creator><![CDATA[SnehaDeep]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/snehadeep/2009/04/28/connection-leak-its-symptoms-and-troubleshooting/</guid>
      <description><![CDATA[To know about connection leak you first need to have a basic idea of connection pooling. If you are...]]></description>
      <content:encoded><![CDATA[<P><FONT size=2>To know about connection leak you first need to have a basic idea of connection pooling. If you are not sure about connection pooling please visit the following link –:</FONT></P>
<P><A title=https://msdn.microsoft.com/en-us/library/ms810829.aspx href="https://msdn.microsoft.com/en-us/library/ms810829.aspx" mce_href="https://msdn.microsoft.com/en-us/library/ms810829.aspx"><FONT size=2>https://msdn.microsoft.com/en-us/library/ms810829.aspx</FONT></A></P>
<P><A title=https://msdn.microsoft.com/en-us/library/8xx3tyca(vs.71).aspx href="https://msdn.microsoft.com/en-us/library/8xx3tyca(vs.71).aspx" mce_href="https://msdn.microsoft.com/en-us/library/8xx3tyca(vs.71).aspx"><FONT size=2>https://msdn.microsoft.com/en-us/library/8xx3tyca(vs.71).aspx</FONT></A></P>
<P><A title=https://support.microsoft.com/default.aspx?scid=kb;%5BLN%5D;191572 href="https://support.microsoft.com/default.aspx?scid=kb;%5BLN%5D;191572" mce_href="https://support.microsoft.com/default.aspx?scid=kb;%5BLN%5D;191572"><FONT size=2>https://support.microsoft.com/default.aspx?scid=kb;%5BLN%5D;191572</FONT></A></P>
<P><FONT size=2></FONT>&nbsp;</P>
<P><FONT size=2>Connection leak basically happens when we open a connection to the database from our application and forget to close it, or for some reasons it doesn’t get closed.</FONT></P>
<P><FONT size=2>To implement connection pooling we basically use these connection string properties –;</FONT></P>
<P><FONT size=2><STRONG>1) Connection Lifetime</STRONG> (Default 0) -&nbsp; When a connection is returned to the pool, its creation time is compared with the current time, and the connection is destroyed if that time span (in seconds) exceeds the value specified by Connection Lifetime. This is useful in clustered configurations to force load balancing between a running server and a server just brought online. A value of zero (0) will cause pooled connections to have the maximum time-out. </FONT></P>
<P><FONT size=2><STRONG>2) Pooling </STRONG>(Default true) -; When true, the connection is drawn from the appropriate pool, or if necessary, created and added to the appropriate pool. </FONT></P>
<P><FONT size=2><STRONG>3) Max Pool Size</STRONG> (Default 100 ) -:The maximum number of connections allowed in the pool.</FONT> </P>
<P><FONT size=2><STRONG>4) Min Pool Size</STRONG> (Default 0 ) -:The minimum number of connections allowed in the pool.</FONT> </P>
<P><FONT size=2><STRONG>5)</STRONG> </FONT><STRONG>Connect Timeout&nbsp; or Connection Timeout</STRONG>&nbsp; (<FONT size=2>Default&nbsp; 15</FONT>) -: <FONT size=2>The length of time (in seconds) to wait for a connection to the server before terminating the attempt and generating an error. </FONT></P>
<P><FONT size=2></FONT></P>
<P><EM><FONT size=2>Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Try <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim cn As New SqlConnection("Integrated Security=SSPI;pooling=true;max pool size=2;Persist Security Info=False;Initial Catalog=master;Data Source=MYSQL2008") </FONT></EM></P>
<P><EM><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cn.Open() <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Catch ex As Exception <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox(ex.Message) <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Try <BR>End Sub</FONT></EM></P>
<P><EM></EM><FONT size=2></FONT>&nbsp;</P>
<P><EM><FONT size=2>In the code above we are opening a connection to a SQL server but not closing it. As a result when this event is triggered third time, we get a error message , as we run out of connections in connection pool. If we simply put a “cn.close”&nbsp; statement in the above code after opening the connection it will never throw an error.</FONT></EM></P>
<P><EM></EM><FONT size=2></FONT>&nbsp;</P>
<P><FONT size=2><EM>Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Try <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim cn As New SqlConnection("Integrated Security=SSPI;pooling=true;max pool size=2;Persist Security Info=False;Initial Catalog=master;Data Source=MYSQL2008") <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim i As Integer <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim a As Integer = 0 </EM></FONT></P>
<P><FONT size=2><EM>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cn.Open() <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i = 5 / a <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cn.Close() <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Catch ex As Exception <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox(ex.Message) <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Try </EM></FONT></P>
<P><FONT size=2><EM>End Sub </EM></FONT></P>
<P><FONT size=2><EM>&nbsp; </EM></FONT></P>
<P><FONT size=2>Now look at this code. Even though we are closing the connection , but still we are facing a connection leak. The reason is that the cn.close is never getting executed as the link above it is throwing an error and the handle is passed over to the exception handling section. This kind of scenario is quite common when the developer thinks that he is closing the connection but still faces a connection leak issue. </FONT></P>
<P><FONT size=2>&nbsp; </FONT></P>
<P><FONT size=2><EM>Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click <BR>&nbsp;&nbsp;&nbsp;&nbsp; Dim cn As New SqlConnection("Integrated Security=SSPI;pooling=true;max pool size=2;Persist Security Info=False;Initial Catalog=master;Data Source=MYSQL2008") </EM></FONT></P>
<P><FONT size=2><EM>&nbsp;&nbsp;&nbsp;&nbsp; Try <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim i As Integer <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim a As Integer = 0 </EM></FONT></P>
<P><FONT size=2><EM>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cn.Open() <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i = 5 / a <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cn.Close() <BR>&nbsp;&nbsp;&nbsp;&nbsp; Catch ex As Exception <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox(ex.Message) <BR>&nbsp;&nbsp;&nbsp;&nbsp; Finally <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cn.Close() <BR>&nbsp;&nbsp;&nbsp;&nbsp; End Try <BR>End Sub </EM></FONT></P>
<P><FONT size=2>To stop this from happening the best thing to do is to close the connection in the “Finally” section like the example above. </FONT></P>
<P><FONT size=2>&nbsp; </FONT></P>
<P><FONT size=2><EM>Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Try </EM></FONT></P>
<P><FONT size=2><EM>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Using cn As New SqlConnection("Integrated Security=SSPI;pooling=true;max pool size=2;Persist Security Info=False;Initial Catalog=master;Data Source=snehach-pri") <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cn.Open() <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Using </EM></FONT></P>
<P><FONT size=2><EM>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Catch ex As Exception <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox(ex.Message) <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Finally </EM></FONT></P>
<P><FONT size=2><EM>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Try <BR>&nbsp;&nbsp;&nbsp; End Sub </EM></FONT></P>
<P><FONT size=2>&nbsp; </FONT></P>
<P><FONT size=2>The code above is another good way to avoid connection leak. Because in the code above the compiler implicitly calls a cn.dispose immediately after the “using” block.</FONT></P>
<P><FONT size=2></FONT>&nbsp;</P>
<P><FONT size=2><EM>Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Try </EM></FONT></P>
<P><FONT size=2><EM>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim cmd As New SqlCommand("select * from emp", getconnection) <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim res As Integer = cmd.ExecuteNonQuery <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getconnection.Close() <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Catch ex As Exception <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox(ex.Message) <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Finally </EM></FONT></P>
<P><FONT size=2><EM>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Try <BR>&nbsp;&nbsp; End Sub </EM></FONT></P>
<P><FONT size=2><EM></EM></FONT>&nbsp;</P>
<P><FONT size=2>Also we need to keep in mind when we get a connection after calling a function which return a connection object, we should always cache the connection object locally and close it. In the above code the getconnection.close is not closing the connection that is used to execute the query but creating another new connection and closing it.</FONT></P>
<P><FONT size=2>&nbsp; </FONT></P>
<H5>Errors related to Connection leak</H5>
<P><FONT size=2>&gt; Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached. </FONT></P>
<P><FONT size=2>&gt; SQL Server Does Not Exist Or Access Denied </FONT></P>
<P><FONT size=2>&gt; General Network Error </FONT></P>
<P><FONT size=2>&nbsp; </FONT></P>
<H5>Ways to confirm that its a connection leak</H5>
<P><FONT size=2>1&gt; Client-Side Performance Counters <BR>NET CLR Data <BR>SqlClient: Current # connection pools <BR>SqlClient: Current # pooled and nonpooled connections <BR>SqlClient: Current # pooled connections <BR>SqlClient: Peak # pooled connections <BR>SqlClient: Total # failed commands <BR>SqlClient: Total # failed connections</FONT></P>
<P><FONT size=2>&nbsp; </FONT></P>
<P><FONT size=2>But these counters most of the time fails to work .&nbsp; And I could not find any other client side counter that always works .&nbsp; </FONT></P>
<P><FONT size=2>&nbsp; </FONT></P>
<P><FONT size=2>2&gt; SQL Server Performance Counter </FONT></P>
<P><FONT size=2>SQLServer:General Statistics <BR>Logins/sec <BR>Logouts/sec <BR>User Connections </FONT></P>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/snehadeep/WindowsLiveWriter/Connectionleakitssymptomsandtroubleshoo_1F66/image_8.png" original-url="https://blogs.msdn.com/blogfiles/snehadeep/WindowsLiveWriter/Connectionleakitssymptomsandtroubleshoo_1F66/image_8.png" mce_href="https://blogs.msdn.com/blogfiles/snehadeep/WindowsLiveWriter/Connectionleakitssymptomsandtroubleshoo_1F66/image_8.png"><IMG title=image style="BORDER-TOP-WIDTH: 0px; DISPLAY: inline; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=279 alt=image src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/snehadeep/WindowsLiveWriter/Connectionleakitssymptomsandtroubleshoo_1F66/image_thumb_3.png" original-url="https://blogs.msdn.com/blogfiles/snehadeep/WindowsLiveWriter/Connectionleakitssymptomsandtroubleshoo_1F66/image_thumb_3.png" width=490 border=0 mce_src="https://blogs.msdn.com/blogfiles/snehadeep/WindowsLiveWriter/Connectionleakitssymptomsandtroubleshoo_1F66/image_thumb_3.png"></A> </P>
<P><U><FONT size=2>Figure 1</FONT></U></P>
<P><FONT size=2>If we take a perfmon with the above counter, A lot of logins with a very few or no logouts indicates a connection leak. In my application I set the connection pool size to 5. since my application is leaking connection, you can see at one time its creating a lot of connections or doing a lot of log-ins and not closing any of them. Once the number of connections reached&nbsp; 5 we got the error. and we closed the application. You can see in the perfmon graph above that all the connection were closed when we closed the application. before that there were no log-outs.</FONT></P>
<P><FONT size=2></FONT>&nbsp;</P>
<P><FONT size=2>3&gt; Profiler</FONT></P>
<P><FONT size=2>Similar to the perfmon result above , A lot of logins with no logouts indicates a connection leak. In the figure below the “ConnTest” is the name of my application. You need to specify the “Application Name =” in the connection string to get it reflected in the profiler. You will see a lot of logouts once you close the application.</FONT></P>
<P><FONT size=2></FONT>&nbsp;</P>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/snehadeep/WindowsLiveWriter/Connectionleakitssymptomsandtroubleshoo_1F66/image_4.png" original-url="https://blogs.msdn.com/blogfiles/snehadeep/WindowsLiveWriter/Connectionleakitssymptomsandtroubleshoo_1F66/image_4.png" mce_href="https://blogs.msdn.com/blogfiles/snehadeep/WindowsLiveWriter/Connectionleakitssymptomsandtroubleshoo_1F66/image_4.png"><IMG title=image style="BORDER-TOP-WIDTH: 0px; DISPLAY: inline; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=190 alt=image src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/snehadeep/WindowsLiveWriter/Connectionleakitssymptomsandtroubleshoo_1F66/image_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/snehadeep/WindowsLiveWriter/Connectionleakitssymptomsandtroubleshoo_1F66/image_thumb_1.png" width=575 border=0 mce_src="https://blogs.msdn.com/blogfiles/snehadeep/WindowsLiveWriter/Connectionleakitssymptomsandtroubleshoo_1F66/image_thumb_1.png"></A> </P>
<P><FONT size=2>Figure 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT></P>
<P><FONT size=2>&nbsp; </FONT></P>
<P><FONT size=2>4&gt; Select * from sysprocesses </FONT></P>
<P><FONT size=2>Run the command “Select * from sysprocesses” , If you see a lot of entries of you application in the result set its quite possible that your application is leaking connection. </FONT></P>
<P><FONT size=2>Once you close your application , You won’t find any such entries in the result set. </FONT></P>
<P><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/snehadeep/WindowsLiveWriter/Connectionleakitssymptomsandtroubleshoo_1F66/image_6.png" original-url="https://blogs.msdn.com/blogfiles/snehadeep/WindowsLiveWriter/Connectionleakitssymptomsandtroubleshoo_1F66/image_6.png" mce_href="https://blogs.msdn.com/blogfiles/snehadeep/WindowsLiveWriter/Connectionleakitssymptomsandtroubleshoo_1F66/image_6.png"><IMG title=image style="BORDER-TOP-WIDTH: 0px; DISPLAY: inline; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=385 alt=image src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/snehadeep/WindowsLiveWriter/Connectionleakitssymptomsandtroubleshoo_1F66/image_thumb_2.png" original-url="https://blogs.msdn.com/blogfiles/snehadeep/WindowsLiveWriter/Connectionleakitssymptomsandtroubleshoo_1F66/image_thumb_2.png" width=342 border=0 mce_src="https://blogs.msdn.com/blogfiles/snehadeep/WindowsLiveWriter/Connectionleakitssymptomsandtroubleshoo_1F66/image_thumb_2.png"></A> </P>
<P><FONT size=2>Figure 3 </FONT></P>
<P><FONT size=2>&nbsp; </FONT></P>
<P><FONT size=2>If you are using Oracle as your database you can sunstitute this command with </FONT></P>
<P><FONT size=2>SELECT LOGON_TIME, OSUSER, PROCESS, MACHINE, PROGRAM <BR>FROM V$SESSION WHERE PROGRAM IS NOT NULL </FONT></P>
<P><FONT size=2>&nbsp; </FONT></P>
<P><FONT size=2>5&gt; Running out of port </FONT></P>
<P><FONT size=2>If your application is leaking connection, It will keep on opening connection without closing them. For opening each connection it will use a port. at one time it might happen that the application box might run out of port. You can track that by the command&nbsp; “Netstat –aon” from the command prompt. If you see a lot of “Time_Wait” in the netstat output , this means that the client box is running out of port. The permanent solution for Connection Leak is always fixing the code. But If you really running out of ports a temporary fix would be to increase the no of ephemeral ports. Ephemeral ports are ports that are used for mainly temporary purpose for opening short lived connection. The no of ephemeral ports varies from 1024 to 65534&nbsp; To increase the no of ephemeral ports </FONT></P>
<P><FONT size=2>Ephemeral ports are ports that are used for mainly temporary purpose for opening short lived connection. we need to change the following registry entries </FONT></P>
<P><FONT size=2>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters </FONT></P>
<P><FONT size=2>On the Edit menu, click New, and then add the following registry entry: <BR>Value Name: MaxUserPort <BR>Value Type: DWORD <BR>Value data: 65534 <BR>Valid Range: 5000-65534 (decimal) <BR>Default: 0x1388 (5000 decimal) <BR></FONT></P>
<P><FONT size=2>We need to increase the value to a higher one eg 65534.</FONT></P>
<P><FONT size=2></FONT>&nbsp;</P>
<P><FONT size=2>Another fix for a lot of time_wait is adjusting the TcpTimedwaitDelay in the registry. This value indicates the amount of time a port will remain in Time_wait state if you do not close the connection. If you decrease this value, the port will be in time_wait state for less amount of time and will be reused sooner.</FONT></P>
<P><FONT size=2>This key is located at -:</FONT></P>
<P><FONT size=2>HKEY_LOCAL_MACHINE\System\CurrectControlSet\services\Tcpip\Parameters <BR>The registry value is: </FONT></P>
<P><FONT size=2>TcpTimedWaitDelay </FONT></P>
<P><FONT size=2>Key: Tcpip\Parameters <BR>Value Type: REG_DWORD - Time in seconds <BR>Valid Range: 30-300 (decimal) <BR>Default: 0xF0 (240 decimal)</FONT> </P>
<P><FONT size=2>We need to decrease this value to a lower one eg 30. </FONT></P>
<P><FONT size=2>NOTE- PLEASE TAKE A COMPLETE BACKUP OF THE BOX BEFORE MAKING ANY CHANGES AND ALSO RESTART THE BOX AFTER CHANGING THE REGISTRY&nbsp; </FONT></P>
<P><EM></EM><FONT size=2></FONT>&nbsp;</P>
<P><EM><FONT size=2></FONT></EM></P>
<P><FONT size=2>For example if you run netstat -aon and you see that close to 4000 connections to the IP address of the target computer that is running SQL Server are in a TIME_WAIT state, you can both increase the default MaxUserPort setting and reduce the TcpTimedWaitDelay setting so that you do not run out of client anonymous ports. For example, you can set the MaxUserPort setting to 20000 and set the TcpTimedWaitDelay setting to 30. A lower TcpTimedWaitDelay setting means that the sockets wait in the TIME_WAIT state for less time. A higher MaxUserPort setting means that you can have more sockets in the TIME_WAIT state.</FONT> </P>
<P><FONT size=2>To know more about MaxUserPort and TcpTimedWaitDelay please refer to&nbsp; </FONT><A title=https://support.microsoft.com/kb/328476 href="https://support.microsoft.com/kb/328476" mce_href="https://support.microsoft.com/kb/328476"><FONT size=2>https://support.microsoft.com/kb/328476</FONT></A> </P>
<P><FONT size=2></FONT></P>
<P><FONT size=2>This is quite typical in applications that leak connections. In some cases, this error only occurs when the customer has migrated a web application from the test environment to the production environment. This is typically because the test server has less memory and garbage collection is run often enough to clean up the leaked connections. In the production environment, the server typically has 2-4 times as much memory as in the test environment, thus there is little memory pressure on the machine to force a garbage collection.</FONT> </P>
<P><FONT size=2></FONT>&nbsp;</P>
<H5>Short time fix for connection leak </H5>
<P><FONT size=2>The parmanent solution for connection leak is always to fix the code. But </FONT><FONT size=2>What if you discovered the connection pooling issue in production and you cannot take it offline to troubleshoot? Turn pooling off. Even though your app will take a performance hit, it shouldn't crash! Your memory footprint will also grow. What if it doesn't crash all that often, and you don't want to take a performance hit? Try this: </FONT></P>
<P><FONT size=2>conn = new SqlConnection(); <BR>try <BR>{ <BR>&nbsp; conn.ConnectionString = "integrated security=SSPI;SERVER=YOUR_SERVER;DATABASE=YOUR_DB_NAME;Min Pool Size=5;Max Pool Size=60;Connect Timeout=2;";&nbsp;&nbsp;&nbsp;&nbsp; // Notice Connection Timeout set to only two seconds! <BR>&nbsp; conn.Open(); <BR>} <BR>catch(Exception) <BR>{ <BR>&nbsp; if (conn.State != ConnectionState.Closed) conn.Close(); <BR>&nbsp; conn.ConnectionString = "integrated security=SSPI;SERVER=YOUR_SERVER;DATABASE=YOUR_DB_NAME;Pooling=false;Connect Timeout=45;"; <BR>&nbsp; conn.Open(); <BR>} </FONT></P>
<P><FONT size=2>If I fail to open a pooled connection within two seconds, I am trying to open a non-pooled connection. This introduces a two second delay when no pooled connections are available, but if your connection leak doesn't show most of the time, this is a good steam valve. </FONT></P>
<P><FONT size=2></FONT></P>
<P><FONT size=2>To Know more about connection pooling please visit the following websites</FONT> </P>
<P><A title=https://support.microsoft.com/default.aspx?scid=kb;%5BLN%5D;191572 href="https://support.microsoft.com/default.aspx?scid=kb;%5BLN%5D;191572" mce_href="https://support.microsoft.com/default.aspx?scid=kb;%5BLN%5D;191572">https://support.microsoft.com/default.aspx?scid=kb;%5BLN%5D;191572</A> </P>
<P><A title=https://support.microsoft.com/kb/313480/en-us href="https://support.microsoft.com/kb/313480/en-us" mce_href="https://support.microsoft.com/kb/313480/en-us">https://support.microsoft.com/kb/313480/en-us</A> </P>
<P><A title=https://msdn.microsoft.com/en-us/library/ms810829.aspx href="https://msdn.microsoft.com/en-us/library/ms810829.aspx" mce_href="https://msdn.microsoft.com/en-us/library/ms810829.aspx">https://msdn.microsoft.com/en-us/library/ms810829.aspx</A> </P>
<P><A title=https://msdn.microsoft.com/en-us/library/aa175863(SQL.80).aspx href="https://msdn.microsoft.com/en-us/library/aa175863(SQL.80).aspx" mce_href="https://msdn.microsoft.com/en-us/library/aa175863(SQL.80).aspx">https://msdn.microsoft.com/en-us/library/aa175863(SQL.80).aspx</A> </P>
<P><A title=https://msdn.microsoft.com/en-us/library/ms810810.aspx href="https://msdn.microsoft.com/en-us/library/ms810810.aspx" mce_href="https://msdn.microsoft.com/en-us/library/ms810810.aspx">https://msdn.microsoft.com/en-us/library/ms810810.aspx</A> </P>
<P><A title=https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring.aspx href="https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring.aspx" mce_href="https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring.aspx">https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring.aspx</A></P>]]></content:encoded>
    </item>
    <item>
      <title>SQL Broker service</title>
      <link>https://docs.microsoft.com/archive/blogs/snehadeep/sql-broker-service</link>
      <pubDate>Tue, 29 Jan 2008 22:50:00 GMT</pubDate>
      <dc:creator><![CDATA[SnehaDeep]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/snehadeep/2008/01/29/sql-broker-service/</guid>
      <description><![CDATA[It basically consists of three parts...]]></description>
      <content:encoded><![CDATA[<P>It basically consists of three parts -:</P>
<P>1)SqlNotificationRequest<BR>2)SqlDependency<BR>3)SqlCacheDependency</P>
<P><BR>Actually the feature in SQL 2005 that delivers notifications on subscriptions for data changes is called Query Notifications </P>
<P>Clients can submit a query requesting to be notified when data was modified in a manner that would change the query result and the server sends a notification when this change occurs. These requests are called ‘query notification subscriptions’. <BR>The list of notification subscriptions can be seen in the server level view sys.dm_qn_subscriptions:<BR>&nbsp;</P>
<P>select * from sys.dm_qn_subscriptions</P>
<P>whhen you submit a query for the notification, the client submits a service name and a broker instance. Each notification subscription begins a Service Broker dialog with this provided service and broker instance. When data is changed and the change would affect the result of the submitted query result, a message is sent on this dialog. By sending this message, the client is considered notified and the notification subscription is removed. If client desires to be notified on further changes, is supposed to subscribe again. </P>
<P mce_keep="true">&nbsp;</P>
<P><STRONG>1) SqlNotificationRequest</STRONG><BR>This is simplest ADO.Net component for subscribing to Query Notifications. This class is used directly to create a query notifications subscription. It consists of three steps - </P>
<P>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Create a new SqlNotificationRequest object, passing in the appropriate Service Broker service name and broker instance</P>
<P>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Assign the newly created SqlNotificationRequest to the Notification property of a SqlCommand</P>
<P>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Execute the SqlCommand.</P>
<P><BR><STRONG>2)SqlDependency</STRONG><BR>This component tries to make the task of handling the Query Notification subscription messages as straightforward as possible. Using the SqlDependency the application developer gets a CLR callback whenever data has changed.</P>
<P><STRONG>3) SqlCacheDependency<BR></STRONG>This is a component designed specifically for ASP.Net to cache data, using the SqlDependency whenever possible.This is just another implementation of the SQL dependency.</P>
<P mce_keep="true">&nbsp;</P>
<P><BR>Common ERRORs of SQL Broker service</P>
<P><BR><EM>2007-10-12 11:18:32.44 spid25s The query notification dialog on conversation handle ‘{EC54573A-9978-DC11-961C-00188B111155}.’ closed due to the following error: ‘&lt;?xml version=”1.0″?&gt;&lt;Error xmlns=”https://schemas.microsoft.com/SQL/ServiceBroker/Error”&gt;&lt;Code&gt;-8490&lt;/Code&gt;&lt;Description&gt;Cannot find the remote service ‘SqlQueryNotificationService-4869b411-fa1c-4d8a-ab37-5bf5762eb98b’ because it does not exist.&lt;/Description&gt;&lt;/Error&gt;’</EM></P>
<P><EM>Reason:</EM></P>
<P>The application is supposed to invoke the static method SqlDependency.<BR>Start&nbsp; at startup to deploy the necessary infrastructure, then use instances of SqlDependency&nbsp; object associated with a SqlCommand to receive callbacks when the query executed is notified (data has changed), and finally call SqlDependency.Stop&nbsp; when the application shuts down to tear down the infrastructure deployed at startup.</P>
<P><BR>The error happens in the following scenario:<BR>1) SqlDependency.Start () is invoked by an application. At this moment a service, a queue and a procedure are created.<BR>2) SqlDependency is used to subscribe to query notifications. Perhaps some queries are notified and re-subscribed, in a normal operations mode<BR>3) Application exists, SqlDependency.Stop is called and the service, queue and procedure are dropped. However, there are still subscribed notifications pending on the server. <BR>4) One or more of the pending subscriptions are notified in the server. This cause a notification message to be sent, but the destination service was dropped, so an error is returned to the sender. The QN receives this error and displays an error message in the ERRORLOG:</P>
<P><BR>A possible workaround would probably have to be based on the kill query notification subscription verb, forcing the application to cleanup any pending subscription at shutdown. Refer to your BOL for more information.<BR></P>]]></content:encoded>
    </item>
    <item>
      <title>Dll path about how a .net application connects to a SQL server</title>
      <link>https://docs.microsoft.com/archive/blogs/snehadeep/dll-path-about-how-a-net-application-connects-to-a-sql-server</link>
      <pubDate>Thu, 10 Jan 2008 05:49:22 GMT</pubDate>
      <dc:creator><![CDATA[SnehaDeep]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/snehadeep/2008/01/10/dll-path-about-how-a-net-application-connects-to-a-sql-server/</guid>
      <description><![CDATA[]]></description>
      <content:encoded><![CDATA[<p><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/snehadeep/WindowsLiveWriter/ThisishowapplicationconnectsSQLserver_E4D2/Dllpath_2.jpg" original-url="https://blogs.msdn.com/blogfiles/snehadeep/WindowsLiveWriter/ThisishowapplicationconnectsSQLserver_E4D2/Dllpath_2.jpg"><img height="453" alt="Dllpath" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/snehadeep/WindowsLiveWriter/ThisishowapplicationconnectsSQLserver_E4D2/Dllpath_thumb.jpg" original-url="https://blogs.msdn.com/blogfiles/snehadeep/WindowsLiveWriter/ThisishowapplicationconnectsSQLserver_E4D2/Dllpath_thumb.jpg" width="531"></a></p>]]></content:encoded>
    </item>
    <item>
      <title>Drivers Used to connect database</title>
      <link>https://docs.microsoft.com/archive/blogs/snehadeep/drivers-used-to-connect-database</link>
      <pubDate>Sun, 06 Jan 2008 12:18:00 GMT</pubDate>
      <dc:creator><![CDATA[SnehaDeep]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/snehadeep/2008/01/06/drivers-used-to-connect-database/</guid>
      <description><![CDATA[SQLOLEDB.dll - OLEDB Driver for&#160; SQL   SQLSRV32.dll - ODBC Driver for SQL     MSDASQL.dll&#160;...]]></description>
      <content:encoded><![CDATA[<p>SQLOLEDB.dll - OLEDB Driver for&#160; SQL   <br />SQLSRV32.dll - ODBC Driver for SQL     <br />MSDASQL.dll&#160; - MSDASQL is an OLEDB provider for ODBC Drivers    <br />MSDAORA.dll - Microsoft OLE DB provider for Oracle&#160; (ODP .NET is Oracles .NET driver for Oracle)    <br />msjet40.dll - Microsoft Jet Engine Library    <br />MSorcl32.dll&#160; - MSorcl32.dll is Microsoft ODBC driver for oracle</p>  <p>Note -&#160; sqlcmd uses OLE DB while Query analyzer and osql uses ODBC ..</p>]]></content:encoded>
    </item>
  </channel>
</rss>