需要在程序中实现类似于 sql server 企业管理器的功能,做成数据库。而且程序是要运行在客户端,给服务器添加新的数据库。。现在遇到了一个问题,就是如何指定做成数据库文件(data ,log)在服务器端的路径。
而且要判断指定的路径,在服务器上是否存在。 并判断服务器端空间是否足够!(就类似于企业管理器中做成数据库时候,指定路径以及判断空间的功能。)急用!

解决方案 »

  1.   

    很多功能完全可以不依赖DMO
    Private Function CreateDatabase(ByVal sDatabase As String, ByVal sDBPath As String, ByVal sLogPath As String) As Boolean
        Dim sSQL As String
        sSQL = "CREATE DATABASE " & sDatabase & " " & vbCrLf & _
               "ON " & vbCrLf & _
               "( NAME = " & Wrap(sDatabase & "_dat") & "," & vbCrLf & _
               "FILENAME = " & Wrap(sDBPath) & "," & vbCrLf & _
               "SIZE = 10, " & vbCrLf & _
               "MAXSIZE = 500, " & vbCrLf & _
               "FILEGROWTH = 5 ) " & vbCrLf & _
               "LOG ON " & vbCrLf & _
               "( NAME = " & Wrap(sDatabase & "_log") & ", " & vbCrLf & _
               "FILENAME = " & Wrap(sLogPath) & "," & vbCrLf & _
               "SIZE = 5MB," & vbCrLf & _
               "MAXSIZE = 25MB," & vbCrLf & _
               "FILEGROWTH = 5MB ) "
        CreateDatabase = ExecuteSQL(sSQL)
    End FunctionDir判断是否有文件存在Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" (ByVal lpRootPathName As String, lpFreeBytesAvailableToCaller As Currency, lpTotalNumberOfBytes As Currency, lpTotalNumberOfFreeBytes As Currency) As Long
    Private Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters As Long) As Long
    判断剩余空间
      

  2.   

    To create a SQL Server database Create a Database object.
    Set the Name property of the Database object.
    Create a DBFile object.
    Set the Name property of the DBFile object.
    Set the PhysicalName property of the DBFile object.
    Set DBFile object properties optional for new database files, such as Size.
    Add the DBFile object to the new Database object FileGroup object named PRIMARY.
    Add the Database object to the Databases collection of a connected SQLServer object
      

  3.   

    To specify a log file Create a LogFile object.
    Set the Name property. 
    Set the PhysicalName property.
    Set the LogFile Size property.
    Add the LogFile object to the LogFiles collection of the TransactionLog object of the new Database object. 
      

  4.   

    SpaceAvailable Property
    The SpaceAvailable property returns the amount of disk resource allocated and unused in operating system files implementing Microsoft® SQL Server™ 2000 database and database transaction log storage.
      

  5.   

    做成数据库的具体过程我已经实现了呀(现在就是直接获取服务器的SQLServer的各种文件的存放路径), 现在就是要弹出一个路径选择的窗口,让用户可以自由选择文件的存放路径(这个窗口显示的是服务器端的路径选择窗口)。 我现在只能对选择本地的路径,所以做成的时候会提示路径出错啊!
     
    就跟企业管理器那个窗口一样啊。 DMO 中有没有这样的一个对象阿,应该有的吧!
      

  6.   

    要路径选择,不要SQL Server里边的默认路径!
      

  7.   

    SQLServer企业管理器中的那个显示服务器端路径的功能,我认为DMO中应该没有,肯定是微软得未公开技术,因为他世界上已经穿透了NT 的安全管理了,如果能够用DMO完成,那么只要你有一个较高的SQLserver权限,也就可以管理NT的文件系统了,太不安全了吧?
    你如找到了,别忘了告诉我一声。
      

  8.   

    看看用 xp_cmdshell 能否得到数据库端的路径。
      

  9.   

    那么sqldmo做成数据库备份方式怎么设定?1 ,整体备份, 2,备份更改过的数据 ,  3 ………… ,4……还有两种不知道什么意思!
      

  10.   

    1 ,整体备份是对整个数据文件(.mdf)做备份,恢复时可以直接恢复
    2,备份更改过的数据是只对上次备份后发生过修改的数据做备份,恢复时必须先从对上次整体备份的恢复开始,然后逐个对差异备份做恢复,直至所要恢复的恢复点(时间点)
      

  11.   

    怎么设置数据库的恢复属性  一共四种如下, 常用的三种option2  -> recovery model         SQLDMORECOVERY_BulkLogged 1        Use the Bulk-Logged Recovery model. 
            SQLDMORECOVERY_Full       2        Use the Full Recovery model. 
            SQLDMORECOVERY_Simple     0        Use the simpleRecovery model. 
            SQLDMORECOVERY_Unknown    3        Recovery model is unknown. 
    怎么在做成数据库的时候,设置为其中一个?用SQLDMO实现!!
      

  12.   

    哈哈,我找到方法了。现在调用sqlserver里的存储过程 sp_dboption
      

  13.   

    调用sqlserver里的存储过程 sp_dboption,已经不是在使用SQLDMO了!option2是谁的属性?
    你用的不是SQLDMO.Restore Object?
    To perform a complete database restore Create a Restore object.
    Set a media property, naming the source device(s).
    Set the Database property to indicate the target database.
    If necessary, set the ReplaceDatabase property to force database creation.
    Call the SQLRestore method. 
    To restore a single unit of a database log Create a Restore object.
    Set the Action property to SQLDMORestore_Log.
    Set a media property, naming the source device(s).
    Set the Database property to indicate the target database.
    Call the SQLRestore method. 
    To restore a database log chain Create a Restore object.
    Set the Action property to SQLDMORestore_Log.
    Set the Database property to indicate the target database.
    Set the LastRestore property to FALSE.
    Set a media property, naming the source device(s).
    Call the SQLRestore method.
    Repeat Steps 5 and 6 for all but the last unit in the database log chain.
    Set the LastRestore property to TRUE.
    Call the SQLRestore method to restore the last unit. 
    To verify the integrity of backup media Create a Restore object.
    Set a media property, naming the source device(s).
    Call the SQLVerify method. 
    Note  The Restore object is compatible with instances of SQL Server 2000 and SQL Server version 7.0. However, the Restore2 object extends the functionality of the Restore object for use with features that are new in SQL Server 2000.
      

  14.   

    是没在用sqldmodboption2, 和dboption 相比就多了一个 RecoveryModel 属性!!其它如readonly 等都一样。在改变一个数据库的OPtion时候, 其它属性都可以 这样设置。。objDatabase.DBOPTION.redyonly = True
      

  15.   

    dim objDatabase as new sqldmo.databaseobjDatabase.DBOPTION.ReadOnly = True
    objDatabase.DBOPTION.SelectIntoBulkCopy= True……………………但是这句就不行
    objDatabase.DBOPTION.RecoveryMode = 1  
    因为DBOPTION里没有这个属性,
    然后Database里不能用DBOPTION2 这个东西
    现在用SQL语句来更改它了ALTER DATABASE   DBName   RECOVERY   SET    SIMPLE/FULL/BULK_LOGGED呵呵,就是抄了系统存储过程sp_dboption里最后的那句话!