[英]Trying to Import data into SQL Server from Access
I tried this small script below. 我在下面尝试了这个小脚本。
USE [Test]
GO
/****** Object: StoredProcedure [dbo].[Import_From_Access] Script Date: 4/16/2017 5:13:19 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[Import_From_Access]
AS
BEGIN
SET NOCOUNT ON;
EXEC sp_addlinkedserver
@server = 'EXCEL-PC\SQLEXPRESS',
@provider = 'Microsoft.Jet.OLEDB.4.0',
@srvproduct = 'OLE DB Provider for Jet',
@datasrc = 'C:\Users\Excel\Desktop\Coding\Microsoft Access\Northwind.mdb'
EXEC sp_addlinkedsrvlogin 'EXCEL-PC\SQLEXPRESS', FALSE, Null, Admin, Null
END
Then, to run it, i tried this: 然后,要运行它,我尝试了以下方法:
SELECT *
FROM OPENQUERY('EXCEL-PC\SQLEXPRESS', 'SELECT * FROM Table1')
Now, I thought that would work, but I'm getting an error message that reads: Msg 102, Level 15, State 1, Line 6 Incorrect syntax near 'EXCEL-PC\\SQLEXPRESS'. 现在,我以为这可以用,但是我收到一条错误消息,内容为:消息102,级别15,状态1,第6行'EXCEL-PC \\ SQLEXPRESS'附近的语法不正确。
I am thinking that the issue may be the '-' character or the '\\' character. 我认为问题可能是“-”字符或“ \\”字符。 unfortunately, that is the name of the server machine, and it's probably not going to change.
不幸的是,这是服务器计算机的名称,并且可能不会改变。 If there a work-around for this kind of thing, or am I just out of luck with this kind of setup?
如果有解决此问题的方法,还是我对这种设置不太满意?
Thanks to all! 谢谢大家!
EXCEL-PC\\SQLEXPRESS
isn't a string literal: EXCEL-PC\\SQLEXPRESS
不是字符串文字:
Try this: 尝试这个:
SELECT *
FROM OPENQUERY([EXCEL-PC\SQLEXPRESS], 'SELECT * FROM Table1')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.