Esempio n. 1
0
 public static ResultInfo.Result TestDatabaseConnection(SetupModels.DatabaseSetup dbModel)
 {
     try
     {
         SqlConnection con = new SqlConnection("Data Source=" + dbModel.Server + ";Initial Catalog=" + dbModel.DatabaseName + ";user id=" + dbModel.User + ";password="******";multipleactiveresultsets=True;application name=EntityFramework");
         con.Open();
         SqlCommand command = new SqlCommand("select * from DynSettings", con);
         command.ExecuteScalar();
         con.Close();
         return(ResultInfo.GenerateOKResult());
     }
     catch (Exception ex)
     {
         return(ResultInfo.GenerateErrorResult(ex.Message));
     }
 }
Esempio n. 2
0
 public static ResultInfo.Result SetDatabaseConnection(SetupModels.DatabaseSetup dbModel)
 {
     try
     {
         var configuration = WebConfigurationManager.OpenWebConfiguration("~");
         var section       = (ConnectionStringsSection)configuration.GetSection("connectionStrings");
         section.ConnectionStrings["DefaultConnection"].ConnectionString = "Data Source=" + dbModel.Server + ";Initial Catalog=" + dbModel.DatabaseName + ";user id=" + dbModel.User + ";password="******";multipleactiveresultsets=True;application name=EntityFramework";
         string con2 = "metadata=res://*/;provider=System.Data.SqlClient;provider connection string='data source=" + dbModel.Server + ";initial catalog=" + dbModel.DatabaseName + ";user id=" + dbModel.User + ";password="******";multipleactiveresultsets=True;application name=EntityFramework'";
         section.ConnectionStrings["DynThingsEntities"].ConnectionString = con2;
         configuration.Save();
         return(ResultInfo.GenerateOKResult("Saved"));
     }
     catch (Exception ex)
     {
         return(ResultInfo.GenerateErrorResult(ex.Message));
     }
 }