dbscript.Connection.server C# (CSharp) Method

server() public method

public server ( ) : Server
return Server
        public Server server()
        {
            ServerConnection conn = serverConnection();
            Server srvr = new Server(conn);
            return srvr;
        }

Same methods

Connection::server ( string database ) : Server

Usage Example

Esempio n. 1
0
        private Database createDB(Connection conn, string dbName, string dbFilePath)
        {
            Server svr = conn.server();
            if (svr.Databases.Contains(dbName) == true)
            {   // drop it like it's hot
                try
                {
                    Console.WriteLine("Database [" + dbName + "] exists. Drop it? Y/n");
                    string ok = Console.ReadLine();
                    if (ok.ToLower() == "y")
                    {
                        //svr.KillDatabase(dbName);
                        Console.WriteLine("Dropping [" + dbName + "]");
                        Database dropme = svr.Databases[dbName];
                        dropme.Drop();
                    }
                    else
                    {
                        return null;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("Didn't drop database [" + dbName + "]");
                    Console.WriteLine("Database may be in use. Try this command again. Otherwise, try dropping the database manually using SQL Server Management Studio, then try again.");
                    //Console.WriteLine(e);
                    svr.KillDatabase(dbName);
                    return null;
                }
            }

            // create new db
            Database db = conn.database(dbName);
            try
            {
                Console.WriteLine("Creating new database [" + dbName + "]");
                db.Create();
            }
            catch (Exception e) // permissions?
            {
                Console.WriteLine("ERROR - create database failed.");
                Console.WriteLine(e.InnerException);
                return null;
            }

            return db;
        }