1、怎么样判断当前有没有安装SQL SERVER?
2、怎么样判断当前的SQL SERVER有没有启动。
3、怎么样启动当前实例NetSDK的实例?
4、怎么样取得当前实例的登录验证方式?是混合验证还是windows身份验证?
5、怎么样创建在已知某个实例和登录用户名和密码的条件下,创建一个数据库和表?
6、怎么样关闭某个实例的sql SERVER服务?
7、怎么样强迫断开某个实例的所有客户端连接?
8、怎么样实现数据库的分离开附加?
9、怎么样把MSDE打包在一起发布?
10、怎么样在程序中自动安装MSDE?每题10分:)

解决方案 »

  1.   

    1.
    1.数据库服务的探测 为了安全,可以让mysql服务运行在内网,但是如果你的机器有外网的接口,mysql也会自动被绑定在外网上面,暴露在internet中,而且系统会在TCP的3306端口监听,非常容易被端口扫描工具发现,不能保证数据安全。如果默认,mssql则会打开TCP的1433端口监听。虽然mssql可以人为的改变监听端口,但是通过微软未公开的1434端口的UDP探测可以很容易知道SQL Server使用的什么TCP/IP端口了。往UDP1434端口 
    发送一个1个字节的内容为02的数据包,被探测的系统则会返回安装的mssql服务信息,这些信息包括:主机名称、实例名称、版本、管道名称以及使用的端口等。这个端口是微软自己使用,而且不象默认的1433端口那样可以改变,1434是不能改变的。一个典型的返回的信息如下: 
    ServerName;Sky;InstanceName;sky;IsClustered;No;Version;8.00.194;tcp;3341;np;\\sky\pipe\MSSQL$XHT310\sql\query; 可以发现mssql的tcp端口改成了3341,为攻击者打开了方便之门!只要会一点socket编程知识,很容易就可以写出扫描mssql服务的程序,而且,由于利用了udp端口,一般的过滤是很难防范的。 补天的awen写了个探测程序,用的是c#语言,代码如下: 
    using System; 
    using System.Net.Sockets; 
    using System.Net; 
    using System.Text; 
    using System.Threading; namespace ConsoleApplication3 
    { class Class1 

    //创建一个UDPCLIENT实例 
    private static UdpClient m_Client; //LISTEN用来获取返回的信息 
    public static string Listen(string hostip) 

    string HostIP = hostip; 
    IPAddress thisIP = IPAddress.Parse(HostIP); 
    IPEndPoint host = new IPEndPoint(thisIP,1434); 
    byte [] data = m_Client.Receive(ref host); 
    Encoding ASCII = Encoding.ASCII; 
    String strData = ASCII.GetString(data); 
    return strData; } 
    //SEND 
    public static void Send(string hostip) 

    string HostIP = hostip; 
    byte [] buffer = {02}; 
    //02为要发送的数据,只有02、03、04有回应 
    int ecode = m_Client.Send(buffer,1,HostIP,1434); 
    //ecode用来返回是否成功发送 
    if(ecode <= 0) 

    Console.WriteLine("发送时出错:" + ecode); } } 
    //对返回的信息的简单的处理 
    public static void OutputInfo(string strdata) 

    string str = strdata; 
    //str.le 
    char [] that = {‘;‘,‘;‘}; 
    string [] strofthis =str.Split(that); 
    //int i= 0  
    for(int i=0;i{ Console.Write(strofthis); 
    Console.Write(‘
    ‘); 
    } } 
    //输入IP 
    public static string InputHostIP() 

    Console.Write("enter the ip you want to scan:"); 
    string hostip =Console.ReadLine(); 
    Console.Write(‘
    ‘); 
    return hostip; 

    //EXIT 
    public static void Exit() 

    Console.WriteLine("if you want to exit ,just input 1
    "); 
    int a = Console.Read(); 
    if(a!= 1) 

    Console.WriteLine("if you want to exit ,just input 1
    "); 
    Console.Read(); 

    else 


    } [STAThread] static void Main(string[] args) 

    string HostIP; 
    HostIP = InputHostIP(); 
    Console.WriteLine("Begin to send udp to the host"); 
    m_Client = new UdpClient(); 
    Send(HostIP); 
    string strData=Listen(HostIP); 
    OutputInfo(strData); 
    Exit(); } 

    } 3一个典型的返回的信息 ServerName;AWEN; 
    InstanceName;AWEN; 
    IsClustered;No; 
    Version;8.00.194; 
    tcp;1044; (TCP的端口,可见就算改了端口也是很容易找到的) 
    np;\\AWEN\pipe\MSSQL$XHT310\sql\query; 
      

  2.   

    7
     1/**//// <summary>
     2        /// 数据库恢复
     3        /// </summary>
     4        public string DbRestore()
     5        {
     6            if(exepro()!=true)//执行存储过程
     7            {
     8                return "操作失败";
     9            }
    10            else
    11            {
    12                SQLDMO.Restore oRestore = new SQLDMO.RestoreClass();
    13                SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
    14                try
    15                {
    16                    exepro();
    17                    oSQLServer.LoginSecure = false;
    18                    oSQLServer.Connect(server, uid, pwd);
    19                    oRestore.Action = SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Database;
    20                    oRestore.Database = database;
    21                    /**////自行修改
    22                    oRestore.Files = @"d:\aaa\aaa.bak";
    23                    oRestore.FileNumber = 1;
    24                    oRestore.ReplaceDatabase = true;
    25                    oRestore.SQLRestore(oSQLServer);
    26
    27                    return "ok";
    28                }
    29                catch(Exception e)
    30                {
    31                    return "恢复数据库失败";
    32                    throw e;
    33                }
    34                finally
    35                {
    36                    oSQLServer.DisConnect();
    37                }
    38            }
    39        }
    40        
    41        /**//// <summary>
    42        /// 杀死当前库的所有进程
    43        /// </summary>
    44        /// <returns></returns>
    45        private bool exepro()
    46        {
    47
    48            SqlConnection conn1 = new SqlConnection("server="+server+";uid="+uid+";pwd="+pwd+";database=master");
    49            SqlCommand cmd = new SqlCommand("killspid",conn1);
    50            cmd.CommandType = CommandType.StoredProcedure;
    51            cmd.Parameters.Add("@dbname","aaa");
    52            try
    53            {
    54                conn1.Open();
    55                cmd.ExecuteNonQuery();
    56                return true;
    57            }
    58            catch(Exception ex)
    59            {
    60                return false;
    61            }
    62            finally
    63            {
    64                conn1.Close();
    65            }
    66        }