我的代码是
use master
go
if exists (select * from sysdatabases where name='bbsDB')
drop database bbsDB
go
exec xp_cmdshell 'mkdir d:\project'
create database bbsDB
on
(
name='bbsDB_data',
filename='d:\project\bbsDB_data.mdf',
size=10,
filegrowth=20%
)
log on
(
name='bbsDB_log',
filename='d:\project\bbsDB_log.ldf',
size=3,
maxsize=20,
filegrowth=10%
)
go
错误提示是
Msg 15281, Level 16, State 1, Procedure xp_cmdshell, Line 1
SQL Server blocked access to procedure 'sys.xp_cmdshell' of component 'xp_cmdshell' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'xp_cmdshell' by using sp_configure. For more information about enabling 'xp_cmdshell', see "Surface Area Configuration" in SQL Server Books Online.
Msg 5133, Level 16, State 1, Line 2
Directory lookup for the file "d:\project\bbsDB_data.mdf" failed with the operating system error 2(系统找不到指定的文件。).
Msg 1802, Level 16, State 1, Line 2
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
这里我为什么不能用xp_cmdshell创建文件,请给出答案

解决方案 »

  1.   

    --这样
    exec master..xp_cmdshell 'mkdir d:\project' 
    --add
    go
      

  2.   

    执行此脚本OKsp_configure 'show advanced options', 1
    GO
    RECONFIGURE
    GO
    sp_configure 'xp_cmdshell', 1
    GO
    RECONFIGURE
    GO
      

  3.   

    那这怎么配置呢,我用的是sql server2008
      

  4.   

    你别说你没有那个运行master..xp_cmdshell这个高级权限,????
      

  5.   

    我用了4楼的代码后变成这样
    use master
    go
    if exists (select * from sysdatabases where name='bbsDB')
    drop database bbsDB
    go
    sp_configure 'show advanced options', 1 
    GO 
    RECONFIGURE 
    GO 
    sp_configure 'xp_cmdshell', 1 
    GO 
    RECONFIGURE 
    GO
    create database bbsDB
    但是还有问题
    Configuration option 'show advanced options' changed from 0 to 1. Run the RECONFIGURE statement to install.
    Configuration option 'xp_cmdshell' changed from 0 to 1. Run the RECONFIGURE statement to install.
    Msg 5133, Level 16, State 1, Line 1
    Directory lookup for the file "d:\project\bbsDB_data.mdf" failed with the operating system error 2(系统找不到指定的文件。).
    Msg 1802, Level 16, State 1, Line 1
    CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
      

  6.   

    这个脚本 只是用来启动 xp_cmdshell 而已 
      

  7.   

    "d:\project\bbsDB_data.mdf"还是没创建好
      

  8.   

    exec xp_cmdshell 'mkdir d:\project'
    你有d:\project 这个路径么?你首先在D盘下 创建一个project文件夹 再试试
      

  9.   

    use master 
    go 
    if exists (select * from sysdatabases where name='bbsDB') 
    drop database bbsDB 
    go 
    exec xp_cmdshell 'mkdir d:\project' 
    create database bbsDB 
    on 

    name='bbsDB_data', 
    filename='d:\project\bbsDB_data.mdf', 
    size=10, 
    filegrowth=20% 

    log on 

    name='bbsDB_log', 
    filename='d:\project\bbsDB_log.ldf', 
    size=3, 
    maxsize=20, 
    filegrowth=10% 

    go 
    就是这个代码 我也是2008
      

  10.   

    sql2005以后 禁用了xp_cmdshell存储过程
    你得按四楼的方式打开