要求: 通过SSIS将Google电子表格数据转换为SQL Server。
方法: 在this网站的帮助下,我正在使用Visual Studio 2015社区版进行编码。我准备了变量,控制流,数据流和添加的脚本组件以及所需的Google参考。
在VS中作为Visual Basic 2015粘贴的代码:
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
Imports Google.GData.Client
Imports Google.GData.Extensions
Imports Google.GData.Spreadsheets
<Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute> 'Line 15 Error here
<CLSCompliant(False)> 'Line 17 Error here
Public Class ScriptMain
Inherits UserComponent
Dim objListFeed As ListFeed
Public Overrides Sub PreExecute()
MyBase.PreExecute()
Dim objService As SpreadsheetsService
Dim objWorkSheetQuery As WorksheetQuery
Dim objWorkSheetFeed As WorksheetFeed
Dim objWorkSheet As WorksheetEntry
Dim objListFeedLink As AtomLink
Dim objListQuery As ListQuery
Dim bt(0) As Byte
'Create a connection to the google account
objService = New SpreadsheetsService("exampleCo-exampleApp-1")
Me.Log(Variables.strPassword, 0, bt)
Me.Log(Variables.strUserName, 0, bt)
objService.setUserCredentials(Variables.strUserName, Variables.strPassword)
Me.Log("Service: " + Variables.strUserName, 0, bt)
'Connect to a specific spreadsheet
objWorkSheetQuery = New WorksheetQuery(Variables.strKey, "private", "full")
objWorkSheetFeed = objService.Query(objWorkSheetQuery)
objWorkSheet = objWorkSheetFeed.Entries(0)
Me.Log("Spreadsheet: " + objWorkSheet.Title.Text.ToString, 0, bt)
'Get a list feed of all the rows in the spreadsheet
objListFeedLink = objWorkSheet.Links.FindService(GDataSpreadsheetsNameTable.ListRel, Nothing)
objListQuery = New ListQuery(objListFeedLink.HRef.ToString())
objListFeed = objService.Query(objListQuery)
Me.Log("ListFeed: " + objListFeed.Feed.ToString, 0, bt)
End Sub
Public Overrides Sub PostExecute()
MyBase.PostExecute()
End Sub
Public Overrides Sub CreateNewOutputRows()
Dim objRow As ListEntry
For Each objRow In objListFeed.Entries
With Output0Buffer
.AddRow()
.Product = objRow.Elements.Item(0).Value
.Qty = objRow.Elements.Item(1).Value
End With
Next
Output0Buffer.EndOfRowset()
End Sub
End Class
问题: 按下Build后,我在第15行和第17行收到以下错误。
BC32035 VB.NET属性说明符不是完整的语句。用一个 line continuation将该属性应用于以下语句。
Here它表示要在属性后添加空格和下划线,但是,当我添加它们时,它们会被自动删除。
答案 0 :(得分:1)
我刚刚在新的SSIS包数据流中创建了一个新的脚本组件,这里是import块和Class声明之间的界限:
' This is the class to which to add your code. Do not change the name, attributes, or parent
' of this class.
<Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute> _
<CLSCompliant(False)> _
Public Class ScriptMain
Inherits UserComponent
我从未听说过你所描述的下划线只是“消失”的情况,但也许如果你将这些线粘贴在你的线上就可以了。
如果没有,您可能需要将代码复制到剪贴板,然后销毁脚本组件并创建一个新组件,并将代码粘贴到其中。