Access to the data inserted in sql

Original link: http://www.cnblogs.com/sbreast/p/3468640.html

Insert into GIS_LZ(xh,lzid,x,y,jzwmc,coord)
SELECT xh,lzid,x,y,jzwmc,coord
FROM OPENDATASOURCE ('Microsoft.Jet.OLEDB.4.0',
'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\公司项目\SugGest_Web\AssetNew\bdc.mdb;User ID=Admin; Password=' )...GIS_LZ

 

Error: linked server "(null)" The OLE DB provider "Microsoft.Jet.OLEDB.4.0" return message "unspecified error."
Message 7303, Level 16, State 1, Line 1
Unable to initialize the linked server "(null)" OLE DB data source object access interface "Microsoft.Jet.OLEDB.4.0" of.

 

Solution:

1.excel文件要关闭

2.将SQL Server(MSSQLSERVER)和SQL Full-Filter Deamon Launcher(MSSQLSERVER)两个服务的登录身份改为LocalSystem
3.执行以下语句:
EXEC sp_configure 'show advanced options' , 1 
GO 
RECONFIGURE 
GO 
EXEC sp_configure 'Ad Hoc Distributed Queries' , 1 
GO 
RECONFIGURE 
GO
 

exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure

4, 'Microsoft.Jet.OLEDB.4.0' can not have spaces
 
 
 


Source: Big turtle
SQL SERVER and ACCESS, EXCEL's data conversion

Familiar SQL SERVER 2000 database administrators know, the DTS can import and export data, in fact, we can also use Transact-SQL statements importing and exporting operation. In the Transact-SQL statements, we mainly use OpenDataSource function, OPENROWSET function, a detailed description of functions, refer to the SQL online help. By the following methods, it can be very easily achieved SQL SERVER, ACCESS, EXCEL data conversion described in detail as follows:

A, SQL SERVER and ACCESS data import and export

Conventional data import and export:

Use DTS Wizard to migrate your Access data to SQL Server, you can use these steps:

1 on Tools in SQL SERVER Enterprise Manager (Tools) menu, select Transformation the Data
2Services (Data Transformation Services), and then select czdImport Data (import data).
3 Select Microsoft Access as the Source in the Choose a Data Source (select the Data Source) dialog box, and then type your .mdb database (.mdb file extension) file name or browse to find the file.
4 In the Choose a Destination (select destination) dialog box, select Microsoft OLE DB Prov ider for SQL Server , select the database server, and then click the necessary authentication.
5 In the Specify Table Copy (copy the prescribed form) or Query (query) dialog box, click Copy tables (replication table).
6 In the Select Source Tables (select the source table) dialog box, click Select All (all selected). Next, Finish.

Transact-SQL statement import and export:

1. queries access data in SQL SERVER in:
- ====================================== ================
the SELECT *
the FROM the OpenDataSource ( 'the Microsoft.Jet.OLEDB.4.0',
'the Data the Source = "C: \ db.mdb"; the Admin the User ID =; Password = ') ... table name
------------------------------------------ -------------------------------------------------- -----
2. access imported Server SQL
- ==================================== ==================
run in SQL SERVER:
the SELECT *
INTO newtable
the FROM the OPENDATASOURCE ( 'Microsoft.Jet.OLEDB.4.0',
'the Data Source = "c: \ DB .mdb "; User ID = Admin; Password = ') ... table
-------------------------------- -------------------------------------------------- ---------------
3.The SQL SERVER table data is inserted into an Access table
- ================================================ ======
run in SQL SERVER:
INSERT INTO the OpenDataSource ( 'the Microsoft.Jet.OLEDB.4.0',
'the Data the Source = "C: \ db.mdb"; the Admin the User ID =; Password =') .. table names
(column names 1, column name 2)
SELECT 1 column names, column names, table 2 from sql
example:
INSERT INTO the OPENROWSET ( 'the Microsoft.Jet.OLEDB.4.0',
'C: \ db.mdb'; 'ADMIN ';' ', the Test)
SELECT ID, name from the Test
the INSERT the INTO the OPENROWSET (' the Microsoft.Jet.OLEDB.4.0 ',' C: \ trade.mdb ';' ADMIN ';' ', table name)
the SELECT *
the fROM sqltablename
-------------------------------------------------- -----------------------------------------------

Two, SQL SERVER and EXCEL data import and export
a query in SQL SERVER data in Excel:
- ============================ ==========================
the SELECT *
the FROM the OpenDataSource ( 'Microsoft.Jet.OLEDB.4.0',
'the Data Source = "c: \ Book1 .xls "; User ID = Admin; Password =; Extended properties = Excel 5.0 ') ... [Sheet1 $]
Here is a sample query, the query program which provides an Excel spreadsheet for Jet by the OLE DB.
* The SELECT
the FROM the OpenDataSource ( 'Microsoft.Jet.OLEDB.4.0',
'the Data Source = "c: \ Finance \ account.xls"; the User ID = Admin; Password =; Extended the Properties = Excel 5.0') ... xactions
- -------------------------------------------------- ----------------------------------------------

2、将Excel的数据导入SQL server :
-- ======================================================
SELECT * into newtable
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="c:\book1.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...[Sheet1$]
实例:
SELECT * into newtable
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="c:\Finance\account.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...xactions
-------------------------------------------------------------------------------------------------

3, SQL SERVER query the data into an Excel file guide
- ================================= =====================
T-SQL Code:
EXEC master..xp_cmdshell 'BCP library name .dbo table name out c: \ Temp.xls -c -. q -S "servername" -U "sa " -P "" '
parameters: S is the SQL server name; the U-user; P is the password
Note: You can also export a variety of formats text file, etc.
example: EXEC master..xp_cmdshell' C OUT saletesttmp.dbo.CusAccount BCP: \ -q -S temp1.xls -C "pmserver" -U "SA" -P "SA" '
EXEC master..xp_cmdshell' BCP "au_fname the SELECT, the au_lname the FROM pubs..authors ORDER BY au_lname "queryout C: \ authors.xls -c -Sservername -Usa -Ppassword '
applied in the EXCEL file export VB6 ADO Code:
Dim CN of As New ADODB.Connection
cn.Open" the SQL Server Driver = {}; Server = WEBSVR; DataBase = WebMis; UID = sa; WD = 123; "
cn.execute "master..xp_cmdshell 'bcp "SELECT col1, col2 FROM 库名.dbo.表名" queryout E:\DT.xls -c -Sservername -Usa -Ppassword'"
------------------------------------------------------------------------------------------------

4, inserting data into Excel in SQL SERVER in:
- ===================================== =================
INSERT INTO the OpenDataSource ( 'the Microsoft.Jet.OLEDB.4.0',
'the Data the Source = "C: \ Temp.xls"; the Admin the User ID =; Password =; Extended properties = Excel 5.0 ' ) ... table1 (A1, A2, A3) values (1,2,3)

T-SQL代码:
INSERT INTO
OPENDATASOURCE('Microsoft.JET.OLEDB.4.0',
'Extended Properties=Excel 8.0;Data source=C:\training\inventur.xls')...[Filiale1$]
(bestand, produkt) VALUES (20, 'Test')
-------------------------------------------------------------------------------------------------

Summary: With the above statement, we can easily data SQL SERVER, ACCESS and EXCEL spreadsheet software conversion, provides a great convenience for us!

Reproduced in: https: //www.cnblogs.com/sbreast/p/3468640.html

Guess you like

Origin blog.csdn.net/weixin_30932215/article/details/94786157
Recommended