Diagnostic methods

Salavat 121 Reputation points
2022-11-25T15:24:10.397+00:00

Prompt possible methods and programs for diagnosing the connection to the SQL server. It is necessary to determine at what stage and which service blocks the connection to the server when using a UWP application)

Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. Salavat 121 Reputation points
    2022-11-29T15:36:26.887+00:00
    private async void Button_Click_CreateNew_DB(object sender, RoutedEventArgs e)  
            {  
                #region try  
                try  
                {  
                    #region   
                    if (n_DB_STRING_CONNECT.IsEnabled == false)  
                    {  
                        SqlConnectionStringBuilder stringBuilder = new SqlConnectionStringBuilder();  
      
                        stringBuilder.Clear();  
      
                        string servAddress = DB_SPEC_NAME_SERVER_ADDRESS.Text;       //This field is filled in from the user from the TextBox - the address in any format (in theory)  
                        string userName = DB_SPEC_UserName.Text;                     /*This field is filled from the user from the TextBox - username with admin   
                                                                      rights (or with the rights to create a database on the server)*/  
                        string userKey = DB_SPEC_KEY_SERVER.Text;                    //This field is filled from the user from the TextBox - the user's password  
                        string mdfFileName = DB_FILE_PATH_DB_INSTALL_MDF.Text;       /*This field is filled in by the user from the TextBox - select where the database file is installed   
                                                                     (example C:\Program Files\Microsoft SQL Server\...\MSSQL\DATA)*/  
                        string ldfFileLogName = DB_LOG_PATH_DB_INSTALL_LDF.Text;     //This field is filled from the user from the TextBox - choose where the log file is installed  
                        string newNameDB = DB_New_Name_DataBase.Text;                //This field is filled from the user from the TextBox - select the name of the database  
      
                        stringBuilder.DataSource = servAddress;                        //Address  
                        stringBuilder.UserID= userName;                                //Name  
                        stringBuilder.Password= userKey;                                //Key  
      
                        string mainArg;  
      
                        using (SqlConnection sqlConnection = new SqlConnection(stringBuilder.ConnectionString))  
                        {                          
                            mainArg = "CREATE DATABASE [" + newNameDB + "] CONTAINMENT = NONE ON  PRIMARY ( NAME = N'" + newNameDB + "', FILENAME = N'" + mdfFileName + "\\" + newNameDB + ".mdf' , SIZE = 524288KB , MAXSIZE = 73000000KB , FILEGROWTH = 250000KB ) LOG ON ( NAME = N'" + newNameDB + "_log', FILENAME = N'" + ldfFileLogName + "\\" + newNameDB + "_log.ldf' , SIZE = 524288KB , MAXSIZE = 83886080KB , FILEGROWTH = 262144KB ) WITH CATALOG_COLLATION = DATABASE_DEFAULT";  
                            SqlCommand sqlCommand = new SqlCommand(mainArg, sqlConnection);  
                            await sqlConnection.OpenAsync();  
                            await sqlCommand.ExecuteNonQueryAsync();  
                            sqlConnection.Close();  
      
                        }  
                    }  
                    #endregion  
      
                }  
                #endregion  
      
                #region Catch  
                catch (System.Exception ex)  
                {  
                    ...  
                }  
                #endregion  
            }  
    
    0 comments No comments