要求:
1。登陆
   有登陆界面,输入用户名和口令后连接sql server服务器,如果登陆的sql server服务器上不存在则建库。
2。建库
   建库时用户可以选择服务器上的路径。如果填写的路径不存在,则提示是否建立。如果存在则建库。

解决方案 »

  1.   

    首先登录到master数据库(不要告诉我说服务器上没有装SQL SERVER。)。
    然后用sp_databases检查有没有需要的数据库。
    建库采用
    create database Sales
    ON 
    ( NAME = Sales_dat,
       FILENAME = 'c:\program files\microsoft sql server\mssql\data\saledat.mdf',
       SIZE = 10,
       MAXSIZE = 50,
       FILEGROWTH = 5 )
    LOG ON
    ( NAME = 'Sales_log',
       FILENAME = 'c:\program files\microsoft sql server\mssql\data\salelog.ldf',
       SIZE = 5MB,
       MAXSIZE = 25MB,
       FILEGROWTH = 5MB )
    都是SQL SERVER帮助里面有的东西。
      

  2.   

    exec xp_cmdshell 'dir ' + 路径
    然后根据结果判断是否存在
      

  3.   

    选择服务器上的路径也可以用exec xp_cmdshell 'dir'然后分析。
    这是逻辑上最简单的做法。
    当然……做起来可能比较麻烦:)
      

  4.   

    你在查询分析器里面执行一下
    exec xp_cmdshell 'dir c:\'就知道什么意思了。这是一个绕过WINDOWS安全机制的办法。
    其他没有好的办法可以知道服务器的全路径。
    当然,如果你是用administrator登录,也可以用\\server\c$的方法访问。
      

  5.   

    有没有sql DMO对象的函数来取得服务器文件列表。
      

  6.   

    >>有没有sql DMO对象的函数来取得服务器文件列表。
    在master 下
    select * from sysdatabases
      

  7.   

    http://dev.csdn.net/article/25/25532.shtm
    获取SQL Server服务器列表的几种方法 一、      SQL DMO描述:SQL Distributed Management Objects(SQL分布式管理对象),存在于SQLDMO.dll文件中,实际上是一个COM 对象,通过调用SQL DMO的ListAvailableSQLServers方法取得。列表类型:列举装有“客户端”和“服务端”的计算机。适用条件:装有 SQL Server,且有SQLDMO.dll文件。速度:中调用示例:GetSQLServerList(ListBox1.items);代码:uses  ComObj; function GetSQLServerList(var AList: TStrings): Boolean;var  SQLServerApp: Variant;  ServerList: Variant;  i: Integer;begin  Result := True;  try    SQLServerApp := CreateOleObject('SQLDMO.Application');    ServerList := SQLServerApp.ListAvailableSQLServers;    for i := 1 to ServerList.Count do      AList.Add(ServerList.Item(i));    SQLServerApp := Unassigned;    ServerList := Unassigned;  except    Result := False;  end;end;
      

  8.   

    select name, filename from sysdatabases中的 fileName 就是你要的吧??我不是上面說過了??
      

  9.   

    他是说取得硬盘上的目录结构
    就好比SelectDirectory函数的效果一样
    应该没有好的办法
    只能用exec xp_cmdshell 'dir c:\'来取。
      

  10.   

    对,就是 windindance(风舞轻扬)的意思。
      

  11.   

    找到了VB的例子。Private Sub cmdDatabaseEnum_Click(Index As Integer)
    Dim db As SQLDMO.Database
    Dim qr As SQLDMO.QueryResults
    On Error GoTo ErrorHandler'Use the pubs database
    Set db = goSQLServer.Databases("pubs")Load frmShowQueryResults
    Select Case Index
      'EnumCandidateKeys method returns a QueryResults
      'object that enumerates the user tables of a Microsoft?SQL Server?
      'database and the constraints on those tables that could define primary keys
      Case 0
        Set qr = db.EnumCandidateKeys
        frmShowQueryResults.QueryResultsCaption = "EnumCandidateKeys"
        
      'EnumDependencies method returns a QueryResults object that enumerates Microsoft?
      'SQL Server?database user objects and user object dependency relationships
      Case 1
        Set qr = db.EnumDependencies(SQLDMODep_Parents)
        frmShowQueryResults.QueryResultsCaption = "EnumDependencies"
        
      'EnumFileGroups method returns a QueryResults object that
      'enumerates the filegroups of a Microsoft?SQL Server?database
      Case 2
        Set qr = db.EnumFileGroups
        frmShowQueryResults.QueryResultsCaption = "EnumFileGroups"
        
      'EnumFiles method returns a QueryResults object that enumerates the operating system
      'files used to implement Microsoft?SQL Server?database storage
      Case 3
        Set qr = db.EnumFiles
        frmShowQueryResults.QueryResultsCaption = "EnumFiles"
        
      'EnumLocks method returns a QueryResults object that enumerates the resource locks held by an instance of Microsoft?SQL Server
      Case 4
        Set qr = db.EnumLocks
        frmShowQueryResults.QueryResultsCaption = "EnumLocks"
        
      'EnumLoginMappings method returns a QueryResults object that contains multiple result sets, where each result set enumerates a Microsoft?SQL Server?login and the database user(s) to which the login is mapped
      Case 5
        Set qr = db.EnumLoginMappings
        frmShowQueryResults.QueryResultsCaption = "EnumLoginMappings"
        
      'EnumMatchingSPs method returns a QueryResults object that enumerates
      'the stored procedures that contain the specified search text
      Case 6
      'if second flag is TRUE thensystem and user-defined stored procedures are
      'enumerated in the QueryResults object.
      'if it is FALSE (default), only user-defined stored procedures are
      'enumerated in the QueryResults object.
        Set qr = db.EnumMatchingSPs("sp_", True)
        frmShowQueryResults.QueryResultsCaption = "EnumMatchingSPs"
        
      'EnumNTGroups method returns a QueryResults object that enumerates the Microsoft?Windows NT?group accounts with permissions in the referenced database
      Case 7
        Set qr = db.EnumNTGroups
        frmShowQueryResults.QueryResultsCaption = "EnumNTGroups"
        
      'EnumUsers method returns a QueryResults object that enumerates the users defined in a Microsoft?SQL Server?database and their role participation
      Case 8
        Set qr = db.EnumUsers
        frmShowQueryResults.QueryResultsCaption = "EnumUsers"
        End SelectfrmShowQueryResults.QueryResults = QueryResultToRecordset(qr)
    frmShowQueryResults.Show vbModal, Me
    Exit SubErrorHandler:
    MsgBox Err.Description
        
    End SubPrivate Sub cmdEnum_Click(Index As Integer)
    Dim qr As SQLDMO.QueryResults
    On Error GoTo ErrorHandlerLoad frmShowQueryResults
    Select Case Index
      'EnumAccountInfo method returns a QueryResults object that enumerates
      'Microsoft?Windows NT?accounts granted access permission to an
      'instance of Microsoft SQL Server?
      Case 0
        Set qr = goSQLServer.EnumAccountInfo
        frmShowQueryResults.QueryResultsCaption = "EnumAccountInfo"
      
      'EnumAvailableMedia method returns a QueryResults object that enumerates
      'media visible by an instance of Microsoft?SQL Server?
      Case 1
        Set qr = goSQLServer.EnumAvailableMedia(SQLDMOMedia_FixedDisk Or SQLDMOMedia_Tape)
        frmShowQueryResults.QueryResultsCaption = "EnumAvailableMedia"
      
      'EnumDirectories method returns a QueryResults object that contains
      'the names of subdirectories held by the user-specified directory
      Case 2
        Set qr = goSQLServer.EnumDirectories("C:\") 'Assume default drive
        frmShowQueryResults.QueryResultsCaption = "EnumDirectories(C:\)"
      
      'EnumErrorLogs method returns a QueryResults object that enumerates
      'the error logs used by an instance of Microsoft?SQL Server?
      Case 3
        Set qr = goSQLServer.EnumErrorLogs
        frmShowQueryResults.QueryResultsCaption = "EnumErrorLogs"
      
      'EnumLocks method returns a QueryResults object that enumerates the
      'resource locks held by an instance of Microsoft?SQL Server
      Case 4
        Set qr = goSQLServer.EnumLocks
        frmShowQueryResults.QueryResultsCaption = "EnumLocks"
      
      'EnumLoginMappings method returns a QueryResults object that contains multiple result sets,
      'where each result set enumerates a Microsoft?SQL Server?login and the database user(s)
      'to which the login is mapped
      Case 5
        Set qr = goSQLServer.EnumLoginMappings
        frmShowQueryResults.QueryResultsCaption = "EnumLoginMappings"
      
      'EnumNTDomainGroups method returns a QueryResults object that enumerates the
      'Microsoft?Windows NT?group accounts defined on a domain
      Case 6
        Set qr = goSQLServer.EnumNTDomainGroups
        frmShowQueryResults.QueryResultsCaption = "EnumNTDomainGroups"
      
      'EnumProcesses method returns a QueryResults object that enumerates the Microsoft?SQL
      'Server?processes running on a referenced instance of Microsoft SQL Server
      Case 7
        Set qr = goSQLServer.EnumProcesses
        frmShowQueryResults.QueryResultsCaption = "EnumProcesses"
      
      'EnumServerAttributes method returns a QueryResults object that enumerates
      'various properties of an instance of Microsoft?SQL Server?
      Case 8
        Set qr = goSQLServer.EnumServerAttributes
        frmShowQueryResults.QueryResultsCaption = "EnumServerAttributes"
      
      'EnumVersionInfo method returns a QueryResults object that enumerates the members
      'of the VERSIONINFO resource that identifies an instance of Microsoft?SQL Server?
      Case 9
        Set qr = goSQLServer.EnumVersionInfo
        frmShowQueryResults.QueryResultsCaption = "EnumVersionInfo"
    End SelectfrmShowQueryResults.QueryResults = QueryResultToRecordset(qr)
    frmShowQueryResults.Show vbModal, Me
    Exit SubErrorHandler:
    MsgBox Err.Description
        
    End Sub'Transforms a QueryResult to a Recordset
    Function QueryResultToRecordset(oQueryResults As SQLDMO.QueryResults) As ADODB.Recordset
    On Error GoTo ErrorHandlerDim sQueryResult As String
    Dim rsQryResults As New ADODB.Recordset
    Dim sRows() As String
    Dim sCols() As String
    Dim idxRow As Long
    Dim idxCol As Long'Create the fields
    For idxCol = 1 To oQueryResults.Columns
      rsQryResults.Fields.Append oQueryResults.ColumnName(idxCol), _
        adVarChar, oQueryResults.ColumnMaxLength(idxCol) + 2
    Next idxCol 'next column
        
    ''Create the recordset rows
    rsQryResults.Open
    For idxRow = 1 To oQueryResults.Rows
      'Add a new record
      rsQryResults.AddNew
      'Add values to each field in the row
      For idxCol = 1 To oQueryResults.Columns
        Debug.Print idxRow, idxCol, oQueryResults.GetColumnString(idxRow, idxCol)
        rsQryResults.Fields(idxCol - 1) = oQueryResults.GetColumnString(idxRow, idxCol)
      Next
      rsQryResults.Update
    Next idxRow' return to caller
    Set QueryResultToRecordset = rsQryResults
    Exit FunctionErrorHandler:
    MsgBox Err.Description
    End FunctionPrivate Sub Form_Unload(Cancel As Integer)
    'Unload frmSQLServersLogin
    End Sub哪位仁兄能把它翻译成Delphi吗?
      

  12.   

    DMO中在远程sql server服务器上创建目录的函数又是什么?
      

  13.   

    >>DMO中在远程sql server服务器上创建目录的函数又是什么?
    用sql dmo 搞不定的, 就用
    exec xp_cmdshell