示例#1
0
        /// <summary>
        /// Checks if the database exists.
        /// </summary>
        /// <param name="name">The database name.</param>
        /// <param name="userName">The user name to connect to database.</param>
        /// <param name="password">The password of the user.</param>
        /// <param name="databaseServerId">The identifier of the the SQL-server where database is placed.</param>
        /// <param name="errorMessage">The error message if an error occured.</param>
        /// <returns>true, if the database exists; otherwise, false.</returns>
        internal static bool DatabaseExists(string name, string userName, string password, Guid databaseServerId, out string errorMessage)
        {
            bool success = false;

            errorMessage = string.Empty;
            MasterDataSet.DatabaseServerRow row = DatabaseServerProvider.GetDatabaseServerRow(databaseServerId);
            if (row != null)
            {
                string        connectionString = CreateConnectionString(name, userName, password, row.Name, row.InstanceName, row.Port);
                SqlConnection connection       = null;
                try
                {
                    connection = new SqlConnection(connectionString);
                    connection.Open();

                    success = true;
                }
                catch (SqlException ex)
                {
                    errorMessage = ex.Message;
                }
                finally
                {
                    if (connection != null)
                    {
                        connection.Dispose();
                    }
                }
            }
            return(success);
        }
示例#2
0
        private static void IncludeAdditionalInfo(ref DataTable table)
        {
            table.Columns.Add("DatabaseServerFullName", typeof(string));
            table.Columns.Add("FullName", typeof(string));
            table.Columns["FullName"].Expression = "'[' + DatabaseServerFullName + '] \\ [' + Name + ']'";

            foreach (DataRow row in table.Rows)
            {
                row["DatabaseServerFullName"] = DatabaseServerProvider.GetDatabaseServerFullName((Guid)row["DatabaseServerId"]);
            }
        }