Ver Mensaje Individual
  #3 (permalink)  
Antiguo 16/06/2009, 06:54
Avatar de pyroCL
pyroCL
 
Fecha de Ingreso: marzo-2009
Ubicación: C#
Mensajes: 261
Antigüedad: 15 años, 3 meses
Puntos: 2
Respuesta: Exportar datos de Excel a SQL SERVER (SIN DTS)

Hola, lo intenté hacer con OPENDATASOURCE desde el editor de SQL, pero al parecer no tengo permisos para hacer ese tipo de query.

SELECT * INTO EMPLEADO FROM OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0',
'Data Source=C:\MAESTRO.xls;Extended Properties=Excel 8.0')...[lista$]

Este es el código que ocupé, al parecer no tiene errores.

Pero me tira este error.
Msg 15281, Level 16, State 1, Line 1
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.

Ya que no me funcionó, lo quiero hacer a través de C# con éste código.

ADODB.Connection cn;
string strSQL;
long IngRecsAff;

cn = new ADODB.Connection();

cn.Open("Provider=SQLOLEDB;Data Source=sdcappdev2;" + "Initial Catalog=Capacitacion;User ID=adm_capacitacion:Password=Desa2009");

strSQL="SELECT PERSONA,D_V,NOMBRE,APELLIDO_PATERNO INTO EMPLEADO (RUT,DIGITO,NOMBRE,APELLIDO_PATERNO) FROM" + "OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0'," + @"'Data Source=C:\Maestro.xls;" + "Extended Properties=Excel 8.0')..[lista$]";

Debug.Print strSQL;

cn.Execute strSQL, IngRecsAff, adExecuteNoRecords;

Debug.Print("Records affected:" + IngRecsAff);

Pero no me funciona, tiene algo mal y no se que es. Por favor si alguien me puede ayudar lo agradecería mucho.