一个小站点,用sql server 2005 express(vs2005自带的)做数据库,需要导入execl,使用了OPENROWSET导入,本机原本出现无法导入的现象,后通过google找到答案,执行:sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ad Hoc Distributed Queries', 1;
GO
RECONFIGURE;
GO就ok了
但我现在在xp上发布,又为xp装上了sql server 2005 express,但在导入时出现如下错误:
SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', see "Surface Area Configuration" in SQL Server Books Online. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
执行了原来的命令还是没用!求解!

解决方案 »

  1.   

    自己坐沙发,补充一点:我在vs 2005中使用的文件系统,执行那段命令是在vs2005中,现在我在本机(vs2005所在的机子)创建了虚拟目录,一样出现问题(无法导入execl),那段命令似乎也没地方执行!在线等,急盼解
      

  2.   

    找了一下,那段应在cmd中执行(sqlcmd –S YourServer\SQLExpress –E)
    似乎也reconfigure了,可还是不行!救命呀!
      

  3.   

    贴上自己的代码:string source = File1.Value;
                SqlConnection myconn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
                myconn.Open();
                string mycom = "insert into student select * from OPENROWSET('MICROSOFT.JET.OLEDB.4.0', 'Excel 5.0;HDR=YES;DATABASE=" + source + "',sheet1$)";
                SqlCommand mycommm = new SqlCommand(mycom, myconn);
                mycommm.ExecuteNonQuery();
                myconn.Close();
      

  4.   

    我的连接字符串,大家看看有没有问题(换个号顶) 
    <connectionStrings>
        <add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True"
          providerName="System.Data.SqlClient" />
      </connectionStrings>
      

  5.   

    google上的解决办法:在sql server 2005 上使用openrowset需要打开2个开关:1. 在注册表查找DisallowAdhocAccess 置为1
    2. 打开ad hoc高级选项sp_configure 'show advanced options', 1;
    GO
    RECONFIGURE;
    GO
    sp_configure 'Ad Hoc Distributed Queries',1
    GO
    RECONFIGURE;
    GO
    可惜还是不行