public ActionResult Check(string provider, string cnn)
        {
            if (string.IsNullOrEmpty(provider))
            {
                return(Json(new ServiceResponse {
                    Success = false, Message = "No provider specified"
                }));
            }

            if (string.IsNullOrEmpty(cnn))
            {
                return(Json(new ServiceResponse {
                    Success = false, Message = "No connectionstring specified to check"
                }));
            }

            var result = false;
            var msg    = "";
            IConnectionStringProvider cnnProvider = null;

            switch (provider)
            {
            case "Json": cnnProvider = JsonConnectionStringProvider.Create();
                break;

            case "AppConfig":
                cnnProvider = new AppConfigConnectionStringProvider();
                break;

            case "InMemory":
                cnnProvider = Utils.CreateInMemoryConnectionStringProvider();
                break;

            default:
                return(Json(new ServiceResponse {
                    Success = false, Message = "Invalid Provider"
                }));

                break;
            }

            using (var con = new SqlConnection(cnnProvider.GetConnectionString(cnn)))
            {
                try
                {
                    con.Open();
                    result = true;
                    con.Close();
                }
                catch (Exception e)
                {
                    msg = e.Message;
                }
            }

            return(Json(new ServiceResponse {
                Success = result, Message = msg
            }));
        }
Exemplo n.º 2
0
        public override void Execute()
        {
            WriteLiteral("\r\n");

            WriteLiteral("\r\n");


            #line 7 "..\..\Areas\Test\Views\DbConnection\Index.cshtml"

            ViewBag.PageTitle = "DbConnection";
            ViewBag.Css       = true;
            ViewBag.Js        = true;

            var jsonConStrProvider      = JsonConnectionStringProvider.Create();
            var appConfigConStrProvider = new AppConfigConnectionStringProvider();
            var inMemoryConStrProvider  = Utils.CreateInMemoryConnectionStringProvider();


            #line default
            #line hidden
            WriteLiteral("\r\n<h3>Manual Check</h3>\r\n<div");

            WriteLiteral(" class=\"form-inline\"");

            WriteLiteral(" id=\"frm-manual-check\"");

            WriteLiteral(">\r\n    <div");

            WriteLiteral(" class=\"form-group\"");

            WriteLiteral(">\r\n        <label");

            WriteLiteral(" for=\"dataSource\"");

            WriteLiteral(">Data Source</label>\r\n        <input");

            WriteLiteral(" type=\"text\"");

            WriteLiteral(" class=\"form-control cnnstr-item\"");

            WriteLiteral(" name=\"dataSource\"");

            WriteLiteral(" id=\"dataSource\"");

            WriteLiteral(" placeholder=\"Data Source\"");

            WriteLiteral(" size=\"10\"");

            WriteLiteral(">\r\n    </div>\r\n\r\n    <div");

            WriteLiteral(" class=\"form-group\"");

            WriteLiteral(">\r\n        <label");

            WriteLiteral(" for=\"initialCatalog\"");

            WriteLiteral(">Initial Catalog</label>\r\n        <input");

            WriteLiteral(" type=\"text\"");

            WriteLiteral(" class=\"form-control cnnstr-item\"");

            WriteLiteral(" name=\"initialCatalog\"");

            WriteLiteral(" id=\"initialCatalog\"");

            WriteLiteral(" placeholder=\"Initial Catalog\"");

            WriteLiteral(" size=\"10\"");

            WriteLiteral(">\r\n    </div>\r\n\r\n    <div");

            WriteLiteral(" class=\"form-group\"");

            WriteLiteral(">\r\n        <label");

            WriteLiteral(" for=\"integratedSecurity\"");

            WriteLiteral(">Integrated Security</label>\r\n        <input");

            WriteLiteral(" type=\"text\"");

            WriteLiteral(" class=\"form-control cnnstr-item\"");

            WriteLiteral(" name=\"integratedSecurity\"");

            WriteLiteral(" id=\"integratedSecurity\"");

            WriteLiteral(" placeholder=\"Integrated Security\"");

            WriteLiteral(" size=\"10\"");

            WriteLiteral(">\r\n    </div>\r\n\r\n    <div");

            WriteLiteral(" class=\"form-group\"");

            WriteLiteral(">\r\n        <label");

            WriteLiteral(" for=\"userId\"");

            WriteLiteral(">User Id</label>\r\n        <input");

            WriteLiteral(" type=\"text\"");

            WriteLiteral(" class=\"form-control cnnstr-item\"");

            WriteLiteral(" name=\"userId\"");

            WriteLiteral(" id=\"userId\"");

            WriteLiteral(" placeholder=\"User Id\"");

            WriteLiteral(" size=\"10\"");

            WriteLiteral(">\r\n    </div>\r\n\r\n    <div");

            WriteLiteral(" class=\"form-group\"");

            WriteLiteral(">\r\n        <label");

            WriteLiteral(" for=\"password\"");

            WriteLiteral(">Password</label>\r\n        <input");

            WriteLiteral(" type=\"text\"");

            WriteLiteral(" class=\"form-control cnnstr-item\"");

            WriteLiteral(" name=\"password\"");

            WriteLiteral(" id=\"password\"");

            WriteLiteral(" placeholder=\"Password\"");

            WriteLiteral(" size=\"10\"");

            WriteLiteral(">\r\n    </div>\r\n\r\n    <button");

            WriteLiteral(" class=\"btn btn-default btn-sm btn-manual-check\"");

            WriteLiteral(">Check</button>\r\n    <div");

            WriteLiteral(" id=\"manual-check-icon\"");

            WriteLiteral(" style=\"display:inline\"");

            WriteLiteral("></div>\r\n</div>\r\n\r\n");


            #line 47 "..\..\Areas\Test\Views\DbConnection\Index.cshtml"
            Write(Html.Partial("Provider", jsonConStrProvider));


            #line default
            #line hidden
            WriteLiteral("\r\n");


            #line 48 "..\..\Areas\Test\Views\DbConnection\Index.cshtml"
            Write(Html.Partial("Provider", appConfigConStrProvider));


            #line default
            #line hidden
            WriteLiteral("\r\n");


            #line 49 "..\..\Areas\Test\Views\DbConnection\Index.cshtml"
            Write(Html.Partial("Provider", inMemoryConStrProvider));


            #line default
            #line hidden
            WriteLiteral("\r\n\r\n");
        }