Search This Blog

Wednesday, October 17, 2018

How can get MSSQL Table, StorePocedures, View & Triggers by query



 Query for Table:


 SELECT COUNT(*) AS TABLECOUNT FROM sys.Tables

Query for Store Procedures:


 select count(*) as ProceduresCount from sys.procedures

Query for Triggers:


 SELECT count(*) AS TriggersCount FROM sys.triggers

Query for Views:


 SELECT count(*) AS ViewsCount FROM sys.views




SELECT 'Count' = COUNT(*), 'Type' = CASE type
                WHEN 'C' THEN 'CHECK constraints'
                WHEN 'D' THEN 'Default or DEFAULT constraints'
                WHEN 'F' THEN 'FOREIGN KEY constraints'
                WHEN 'FN' THEN 'Scalar functions'
                WHEN 'IF' THEN 'Inlined table-functions'
                WHEN 'K' THEN 'PRIMARY KEY or UNIQUE constraints'
                WHEN 'L' THEN 'Logs'
                WHEN 'P' THEN 'Stored procedures'
                WHEN 'R' THEN 'Rules'
                WHEN 'RF' THEN 'Replication filter stored procedures'
                WHEN 'S' THEN 'System tables'
                WHEN 'TF' THEN 'Table functions'
                WHEN 'TR' THEN 'Triggers'
                WHEN 'U' THEN 'User tables'
                WHEN 'V' THEN 'Views'
                WHEN 'X' THEN 'Extended stored procedures'
    END

    FROM sys.objects
    GROUP BY type
    ORDER BY type



Count
Type
5
NULL
47
NULL
3
NULL
62
Default or DEFAULT constraints
33
FOREIGN KEY constraints
27
Stored procedures
45
System tables
1
Table functions
54
User tables







Thursday, September 20, 2018

G-Suits Issue - SmtpException: Unable to read data from the transport connection: net_io_connectionclosed



Common error in G-suits account for sending  SMTP mail .


When getting error :


G-Suits Issue - SmtpException: Unable to read data from the transport connection: net_io_connectionclosed


Solution : 


The most simple way to test is to try using port 587 and not 465. While some SMTP servers support TLS on 465 (and sometimes even 25), only port 587 is required to support TLS. 



 SmtpClient sm = new SmtpClient();
            sm.EnableSsl = true;
            sm.Host = "smtp.gmail.com";
            sm.Port = 587;//465;
            sm.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            sm.UseDefaultCredentials = false;
            sm.Credentials = new NetworkCredential("email", "password");
            sm.ServicePoint.MaxIdleTime = 1;
            sm.Send(ms);
            ms.Dispose();



Tuesday, December 19, 2017

What is sendgrid ??

SendGrid is a cloud-based SMTP provider that allows you to send email without having to 

maintain email servers. SendGrid manages all of the technical details, from scaling the 

infrastructure to ISP outreach and reputation monitoring to whitelist services and real time

analytics.

SendGrid mail code:

using SendGridMail;
using SendGridMail.Transport;


public bool SendEmailThroughSendGrid(string MailTo, string DisplayName, string Subject, string MailFrom, string MailBody)
    {
        try
        {
            string sgUsername = "***********";
            string sgPassword = "***************";
            SendGrid myMessage = SendGrid.GetInstance();
            myMessage.AddTo(MailTo);
            myMessage.From = new MailAddress(MailFrom, DisplayName);
            myMessage.Subject = Subject;
            myMessage.Text = "";
            myMessage.Html = MailBody;
            var credentials = new NetworkCredential(sgUsername, sgPassword);
            var transportWeb = Web.GetInstance(credentials);
            transportWeb.Deliver(myMessage);
            return true;
        }
        catch (Exception)
        {
            return false;
        }
        finally
        {

        }
    }




Error: The program '[3148] iisexpress.exe' has exited with code -1073741816 (0xc0000008) 'An invalid handle was specified'.

Process with an ID #### is not running on Visual Studio 2015

Error:

The program '[3148] iisexpress.exe' has exited with code -1073741816 (0xc0000008) 'An invalid handle was specified'.

1.       Delete the \Documents\IISExpress folder using the following console command: rmdir /s /q "%userprofile%\Documents\IISExpress"
2.       Delete the applicationhost.config file which is placed within the \.vs\Config\ folder in your Visual Studio project root folder.
3.       Close Visual Studio and re-start it with Administrative (right-click > Run as Administrator).
The .vs is a hidden folder so you have to enable the Show hidden files, folders, and drives option in Windows Explorer.

E:\CP\xxxxxx\.vs\config




we create an application at IIS and enable the windows authentication then it is stored ApplicationHost.config as


         <sites>
            <site name="WebSite1" id="1" serverAutoStart="true">
                <application path="/">
                    <virtualDirectory path="/" physicalPath="%IIS_SITES_HOME%\WebSite1" />
                </application>
                <bindings>
                    <binding protocol="http" bindingInformation=":8080:localhost" />
                </bindings>
            </site>
            <site name="xxxxxxx" id="2">
                <application path="/" applicationPool="Clr4IntegratedAppPool">
                    <virtualDirectory path="/" physicalPath="E:\CP\xxxxxxx\webadhar" />
                </application>
                <bindings>
                    <binding protocol="http" bindingInformation="*:65417:localhost" />
                </bindings>
            </site>

Friday, June 16, 2017

How can restore a backup on lower version of SQL Server:

How can restore a backup on lower version of SQL Server:

We have SQL command to find out SQL version.
SELECT @@VERSION  by this commant we can find out our SQL version.


Out Put:
Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64)   Apr  2 2010 15:48:46   Copyright (c) Microsoft Corporation  Developer Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )

Meaning of 4 digit output - 10.50.1600.1
1st digit product version (8 means, SQL 2000, 9 means SQL 2005, 10 means SQL 2008, 11 means SQL 2012).
2nd digit product level - different releases have different numbers. 10.00 is SQL 2008, 10.50 is SQL 2008 R2.
3rd digit - Service Pack to you SQL Server installation.
4th digit - one is a build number

Three cases we will face when restore SQL database one version to other version:
Source server is an older version and target server is a newer version of SQL Server.
For example:
Source: 9.00.2234.0 (SQL 2005)
Target: 10.00.5500.0 (SQL 2008 SP2)
Backups are compatible. You can restore a database backup on a newer version of SQL Server.

Source server and target server are the same product version and product level. They may differ on 3rd  or 4th  digit  in the version number.
For example:
Source server is 10.50.2876.0 and target is 10.50.2799.0.
Backups are compatible. Microsoft does not introduce significant changes in BACKUP/RESTORE functionality that breaks backward compatibility by a hotfix or Service Pack.
Source server and target server differ by 1st  or 2nd  digit - a product version or a product level and the target is older than the source.
For example:
Source: 11.00.2100 (SQL 2012)
Target: 10.00.5500 (SQL 2008 SP2)
Backups are incompatible. 

Thursday, June 8, 2017

Dynamic Message box, Alert Message popup box with java script

How can create Dynamic Alert Message box :



Evert times we need confirmation after data created or updated in database. In this case we can make one popup message box with help of java script we can also put dynamic value in this popup message box.

1 STEP:  Create 2 two function one for show message box or second one for hide message box.

2 STEP: Write CSS for message box design.

3 STEP: Create div where display message.

4 STEP: Write our message in label control in cs page.

1 STEP:

<script type="text/javascript">
    function ShowDialog(modal) {
      
        $("#overlay").show();
        $("#dialog").fadeIn();
        if (modal) {
            $("#overlay").unbind("click");
        }
        else {
            $("#overlay").click(function (e) {
                HideDialog();
            });
        }
        return false;
    }

    function HideDialog() {
        $("#overlay").hide();
        $("#dialog").fadeOut(300);

    }

</script>

2 STEP:<style type="text/css">
.web_dialog_overlaycm
{
    position: fixed;
    top: 25%;
    right: 0%;
    bottom: 5%;
    left: 40%;
    height: 29%;
    width: 56%;
    margin: 0;
    padding: 0;
    background: #f3c022;
    -moz-opacity: .15;
    z-index: 20000;
    display: none;
}

.web_dialogcm
{
    display: none;
    position: fixed;
    width: 54%;
    height: 24%;
    top: 27%;
    left: 41%;
    background-color: #ffffff;
   /* border: 1px solid #993333;*/
    border: 1px solid #5db2ff;
    padding: 0px;
    z-index: 20000;
    font-family: Verdana;
    font-size: 10pt;
}
    .style1
    {
        width: 100%;
    }
</style>

3 STEP:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <table class="style1">
        <tr>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
                
            </td>
            <td>
                &nbsp;</td>
        </tr>
    </table>
   <div id="overlay" class="web_dialog_overlaycm" style="width: 20%; float: center;">
                <div id="dialog" class="web_dialogcm" style="width: 18%; float: center;">
                    <div style="width: 100%; float: center;">
                        <table style="width: 100%;">
                            <tr align="center">
                                <td style="text-align: center;">
                                  
                                </td>
                            </tr>
                             <tr align="center">
                                <td style="text-align: center;">
                                  
                                </td>
                            </tr>
                            <br>
                             <tr align="center">
                                <td style="text-align: center;">
                                    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                                </td>
                            </tr>
                           
                           
                        </table>
                    </div>
                    <div style="width: 100%; float: left;">
                        <table id="tblZoom" style="width: 200px;" align="center">
                            <tr id="Zoom1" runat="server">
                                <td id="Td2" runat="server">
                                    <div id="divZoom" style="border: 1px solid #5db2ff; float: center; vertical-align: top;"
                                        align="center">
                                    </div>
                                </td>
                            </tr>
                            <br>
                             <tr align="center">
                                <td style="text-align: center;">
                                  
                                </td>
                            </tr>
                             <tr align="center">
                                <td style="text-align: center;">
                                    
                                </td>
                            </tr>
                             <tr align="center">
                                <td style="text-align: center;">
                                    <input id="btnClose" type="button" value="OK" onclick="HideDialog()" />
                                </td>
                            </tr>
                           
                        </table>
                    </div>
                </div>
            </div>
    </form>
</body>
</html>

4 STEP:

using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Web;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
       
        Label1.Text = "Country Created Or Updated Sucessfully In Database.";

        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "function", "ShowDialog(true);", true);
    }
}




Saturday, March 25, 2017

Publish your package on NPM - node package manager

Now a good new for every developer you can publish your own package on NPM, you just have to follow mentioned step...


Publish your package on NPM - node package manager, publish your javascript library on npm, publish your javascript library on cdn

Wednesday, July 20, 2016

SQL SERVER – Clear Dropdown List of Recent Connection from SQL Server Management Studio








For SQL 2005, delete the file:

C:\DocumentsSettings\<USER>\ApplicationData\Microsoft\MicrosoftSQL Server\90\Tools\Shell\mru.dat

For SQL Server 2008, delete the file::

C:\Documents and Settings\<user>\Application Data\Microsoft\Microsoft SQL Server\100\Tools\Shell\mru.dat
C:\Documents and Settings\[user]\Application Data\Microsoft\Microsoft SQL Server\100\Tools\ShellSEM\mru.dat




Resolving view state message authentication code (MAC) errors

Server Error in '/' Application.

Validation of viewstate MAC failed. If this application is hosted by a web farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
Source Error: [No relevant source lines]
Source File: ... Line: 0
Stack Trace:

[ViewStateException: Invalid viewstate.
Client IP: ::1
Port: 40653
Referer: http://localhost:40643/MyPage.aspx
Path: /MyPage.aspx
User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)
ViewState: ...]

[HttpException (0x80004005): Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

See http://go.microsoft.com/fwlink/?LinkID=314055 for more information.]
System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) +190
System.Web.UI.ViewStateException.ThrowMacValidationError(Exception inner, String persistedState) +46
System.Web.UI.ObjectStateFormatter.Deserialize(String inputString, Purpose purpose) +861
System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter2.Deserialize(String serializedState, Purpose purpose) +51
System.Web.UI.Util.DeserializeWithAssert(IStateFormatter2 formatter, String serializedState, Purpose purpose) +67
System.Web.UI.HiddenFieldPageStatePersister.Load() +444
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +368
System.Web.UI.Page.LoadAllState() +109
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +7959
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +429
System.Web.UI.Page.ProcessRequest() +125
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +48
System.Web.UI.Page.ProcessRequest(HttpContext context) +234
ASP.mypage_aspx.ProcessRequest(HttpContext context) in ...:0
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +1300
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +140

Resolve this issue you can add a <machineKey> element, in the Web.config file. The <machineKey> element is only valid in the Web.config file at the root of your application and is not valid at the subfolder level.

<configuration>
  <system.web>
    <machineKey ... />  (add below machineKey in system.web section)
  </system.web>
</configuration>

<machineKey
validationKey="20A1D0BF6A9C13FC54FAFAE5534D586F78A50005223F08C0C8AD0704CCF27C29E6F41C30FA03D9E418F7EBB38BFDAC698545C39200C39A622BE22EBC6C10BEE8"
decryptionKey="CD0F6DC238FD884B009B3C5E3163726F58C4D51FE82908E9F1504BF50D95075D"
validation="SHA1" decryption="AES"/>