SqlServerDbaServices

Provides DBA services for Microsoft SQL Server.

Namespace:
KpokPatagon.Data.SqlServer.Dba
Type:
Class
Public:
Yes
Protected:
No
Sealed:
Yes
Abstract:
No

Constructors

SqlServerDbaServices

Initializes a new instance of SqlServerDbaServices.

Signature:
public Void SqlServerDbaServices(databaseApi, formatter)
Parameters
Name Type Summary
databaseApi IDbAccess
formatter IDbFormatter

Properties

DatabaseApi

Database communication API.

Signature:
public IDbAccess DatabaseApi { get; }

Formatter

An IDbFormatter for Sql Server.

Signature:
public IDbFormatter Formatter { get; }

Methods

ChangeLoginPassword

Changes the login password.

Signature:
public Void ChangeLoginPassword(login)
Parameters
Name Type Summary
login Login A Login to create.
Exceptions
Type Summary
ValidationException Thrown when login does not have the required configuration.
ArgumentNullException Thrown when login is null.
SchemaManipulationException Thrown when an error occurs while manipulating the database.

CreateDatabase

Creates a new database.

Signature:
public Void CreateDatabase(name, collate, autoCloseOff, autoShrinkOff)
Parameters
Name Type Summary
name String Name of the database.
collate String Collation for the database (optional).
autoCloseOff Boolean Whether to issue an AUTO_CLOSE OFF command.
autoShrinkOff Boolean Whether to issue an AUTO_SHRINK OFF command.
Exceptions
Type Summary
SchemaManipulationException Thrown when an error occurs while manipulating the database.
ArgumentNullOrEmptyException Thrown when name is null or empty.

CreateLogin

Creates a new login.

Signature:
public Void CreateLogin(login)
Parameters
Name Type Summary
login Login A Login to create.
Exceptions
Type Summary
ValidationException Thrown when login does not have the required configuration.
ArgumentNullException Thrown when login is null.
SchemaManipulationException Thrown when an error occurs while manipulating the database.

CreateUser

Creates a user for login in the database database and adds the user to the specified roles.

Signature:
public Void CreateUser(userName, login, database, roles)
Parameters
Name Type Summary
userName String Name of the user to add.
login String Name of the login the user is added for.
database String Name of the database to add the user to.
roles UserRoles User roles to be granted to the new user.
Exceptions
Type Summary
SchemaManipulationException Thrown when an error occurs while manipulating the database.
ArgumentNullOrEmptyException Thrown when userName is null or empty.
ArgumentNullOrEmptyException Thrown when login is null or empty.
ArgumentNullOrEmptyException Thrown when database is null or empty.

DropDatabase

Drops a database.

Signature:
public Void DropDatabase(name)
Parameters
Name Type Summary
name String Name of the database to drop.
Exceptions
Type Summary
SchemaManipulationException Thrown when an error occurs while manipulating the database.
ArgumentNullOrEmptyException Thrown when name is null or empty.

DropLogin

Drops a login.

Signature:
public Void DropLogin(name)
Parameters
Name Type Summary
name String Name of the login to drop.
Exceptions
Type Summary
SchemaManipulationException Thrown when an error occurs while manipulating the database.
ArgumentNullOrEmptyException Thrown when name is null or empty.

DropSchema

Drops a schema in the database.

Signature:
public Void DropSchema(name, database)
Parameters
Name Type Summary
name String Name of the schema.
database String Name of the database.
Exceptions
Type Summary
SchemaManipulationException Thrown when an error occurs while manipulating the database.
ArgumentNullOrEmptyException Thrown when name is null or empty.
ArgumentNullOrEmptyException Thrown when database is null or empty.

DropUser

Drops a user named name from the database.

Signature:
public Void DropUser(name, database)
Parameters
Name Type Summary
name String Name of the user to drop.
database String Name of the database from where the user is dropped.
Exceptions
Type Summary
SchemaManipulationException Thrown when an error occurs while manipulating the database.
ArgumentNullOrEmptyException Thrown when name is null or empty.
ArgumentNullOrEmptyException Thrown when database is null or empty.

ExistsDatabase

Checks whether a database exists on the server.

Signature:
public Boolean ExistsDatabase(name)
Returns

true if the database exists, otherwise false.

Parameters
Name Type Summary
name String Name of the database to check.
Exceptions
Type Summary
SchemaManipulationException Thrown when an error occurs while accesing the database.
ArgumentNullOrEmptyException Thrown when name is null or empty.

ExistsLogin

Checks whether a login exists.

Signature:
public Boolean ExistsLogin(name)
Returns

true if the login exists, otherwise false.

Parameters
Name Type Summary
name String Name of the login to check.
Exceptions
Type Summary
SchemaManipulationException Thrown when an error occurs while accesing the database.
ArgumentNullOrEmptyException Thrown when name is null or empty.

ExistsUser

Checks whether a user exists within a database.

Signature:
public Boolean ExistsUser(userName, databaseName)
Returns

true if the user exists within the database, otherwise false.

Parameters
Name Type Summary
userName String Name of the user to verify.
databaseName String Name of the database to which the user belongs.
Exceptions
Type Summary
SchemaManipulationException Thrown when an error occurs while accesing the database.
ArgumentNullOrEmptyException Thrown when userName is null or empty.
ArgumentNullOrEmptyException Thrown when databaseName is null or empty.

GetServerRoles

Gets the server roles for the spacified userName.

Signature:
public ServerRoles GetServerRoles(userName)
Returns

A flagged enumeration of the user server roles.

Parameters
Name Type Summary
userName String Name of the user to get it's server roles.
Exceptions
Type Summary
SchemaManipulationException Thrown when an error occurs while manipulating the database.
ArgumentNullOrEmptyException Thrown when userName is null or empty.