Google Spreadsheet to SSIS VB Code issue - visual-studio

Requirement:
Convert Google Spreadsheet data to SQL Server through SSIS.
Method:
With help from this website, I'm doing coding in Visual Studio 2015 Community edition. I have prepared Variables, Control Flow, Data Flow and added Script component and the required Google References.
Code pasted in VS as 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
Problem:
Upon pressing Build, I get the following error on Line 15 and 17.
BC32035 VB.NET Attribute specifier is not a complete statement. Use a
line continuation to apply the attribute to the following statement.
Here it says to add a space and underscore following the attribute, however, when I add them they are just automatically removed.

I just created a new script component in a new SSIS package dataflow, and here are the lines between the import block and the Class declaration:
' 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
I have never heard of the situation you describe where the underscores just "disappear", but maybe if you paste these lines over your lines it will work.
If not, you may need to copy your code to the clipboard, and then destroy the script component and create a new one, and paste your code into it.

Related

ASP Classic "Microsoft VBScript runtime error '800a01a8' Object required: 'hashHelp'"

Here I have a double Directory that is suppose to be carrying information from a database in the form of the object hashHelp. Clearly, this isn't working.
Based on everything I've found on this website and around the web, this error message seems to imply that the object hashHelp isn't being created, but you can clearly see it being created above. I have check Any idea what could be happening?
do until rs.eof
if valid(cart, rs, data) = true then
Dim hashHelp
Set hashHelp = new HashHelper
hashHelp.setCode(rs.Fields("Code"))
hashHelp.setDateTime(rs.Fields("ScanTime"))
Dim entry
entry = DateDiff("d", beginDate, DateValue(rs.Fields("ScanTime")))
hash.Item(rs.Fields("ScanTime")).Item(arr(entry)) = hashHelp
arr(DateDiff("d", beginDate, rs.Fields("ScanTime"))) = arr(DateDiff("d", beginDate, rs.Fields("ScanTime"))) + 1
End If
rs.movenext
loop
rs.close
The line the error happens on is hash.Item(rs.Fields("ScanTime")).Item(arr(entry)) = hashHelp
I've checked all the other variable and they are being created and used just fine.

TFS 2010 tracking build definition changes?

Is there a way to track changes to a build definition in TFS 2010? Please go to 'Team Explorer > ProjectName > Builds' in visual studio to see what I am talking about. You need to have access to a TFS server in order to see what I am referring to. Now once you are in the Team Explorer> ProjectName > Builds, you can create a build definition to compile your csproj or sln files on TFS. What I am wondering is, Is there a way to version these build definitions if I do any changes to existing ones or add a new one?
I got into the same issue when someone from the team modified the Build Definition, I tried to find all the available option but found none except Xeam Build Definition Extension which is only supported VS 2012 onward and has some downsides, so finally to get the immediate work around I wrote a small app which returns the Last Modified By and Last Modified Date and the complete Build Definition details which you can compare with previous version to find what got changed.
Imports Microsoft.TeamFoundation.Build.Client
Private Const RootFolder As String = "C:\TFS Utility Reports\"
''' <summary>
''' To Get the Build Definition Details
''' </summary>
''' <param name="teamProjectName"></param>
''' <param name="buildDefinitionName"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function GetBuildDefinitionDetails(teamProjectName As String, buildDefinitionName As String) As String
Dim buildDefinitionSummary As String = Nothing
Dim buildDefinitionDetails As String = Nothing
Dim reportPath As String = RootFolder & "Build Definitions\" & buildDefinitionName
Dim buildDefinitionDetailsFileName As String = reportPath & "\" & buildDefinitionName & "_" & Date.Now.ToString(CultureInfo.CurrentCulture).Replace("/", String.Empty).Replace(":", String.Empty) & ".txt"
Dim buildService = CType(TfsTeamProjectCollection.GetService(GetType(IBuildServer)), IBuildServer)
Dim buildDefinition As IBuildDefinition = buildService.GetBuildDefinition(teamProjectName, buildDefinitionName)
If buildDefinition IsNot Nothing Then
GetAllBuildDefinitions(teamProjectName)
buildDefinitionSummary = buildDefinition.ToString()
UpdateFile(buildDefinitionSummary, buildDefinitionDetailsFileName, reportPath)
If buildDefinition.Workspace IsNot Nothing Then
buildDefinitionDetails = String.Format(CultureInfo.CurrentCulture, "Last Modified By: {0}, Last Modified Date: {1}",
buildDefinition.Workspace.LastModifiedBy,
buildDefinition.Workspace.LastModifiedDate)
End If
End If
Return buildDefinitionDetails
End Function
''' <summary>
''' Generate Log/Summary/Report
''' </summary>
''' <param name="lineToWrite"></param>
''' <param name="filePath"></param>
''' <param name="folderPath"></param>
''' <remarks></remarks>
Private Shared Sub UpdateFile(ByVal lineToWrite As String, ByVal filePath As String, ByVal folderPath As String)
Dim strFileName As String = String.Empty
lineToWrite = lineToWrite.Trim()
strFileName = filePath
Dim di As IO.DirectoryInfo = New IO.DirectoryInfo(folderPath)
If Not di.Exists Then
di.Create()
End If
Dim streamWriter As New StreamWriter(strFileName, True, System.Text.Encoding.ASCII)
Try
Dim strOutput As String
strOutput = lineToWrite.ToString
streamWriter.WriteLine(strOutput)
Catch ex As Exception
Throw
Finally
streamWriter.Dispose()
End Try
End Sub
There is no way to track changes to a build definition. If you have multiple branches / versions you need to build I suggest creating a different build definition.
Some of the properties can be set when you queue the build, so if you want a CI build that does not copy it's output to the drop server, you can have that, but then if you want to deploy a version you can set a drop folder when you queue the build.
In the TFS Power Toys you get a "Clone Build Definition" context menu so you can copy builds easier if you have a lot of settings you want to keep similar.
There is a way. There is this tool in the vsgallery:
http://visualstudiogallery.msdn.microsoft.com/ec36f618-d122-48a3-8236-7d9cd19791ee
I used it with tfs2012. I don't know if it works with tfs2010

Getting Error as 'User defined type not defined' in the code

Greetings for the day,
Hi, I am a beginner using vb 6.0. I am using the following code and getting 'user defined type not defined'.the code is below.the line where i get error is highlighted.Kindly help.should i add some references or components?if so,what it would be. your timely and kindly help will be much more helpful for me
Public Sub LoadDocument()
Dim xDoc As MSXML2.DOMDocument
Set xDoc = New MSXML2.DOMDocument
xDoc.async = False
xDoc.validateOnParse = False
If xDoc.Load("C:\Users\284582\Desktop\XML1.xml") Then
DisplayNode xDoc.ChildNodes, 0
End If
End Sub
' Error on this line'
Public Sub DisplayNode(ByRef Nodes As MSXML.IXMLDOMNodeList, _
ByVal Indent As Integer)
Dim xNode As MSXML.IXMLDOMNode
Indent = Indent + 2
For Each xNode In Nodes
If xNode.NodeType = NODE_TEXT Then
Debug.Print Space$(Indent) & xNode.ParentNode.nodeName & _
":" & xNode.NodeValue
End If
If xNode.HasChildNodes Then
DisplayNode xNode.ChildNodes, Indent
End If
Next xNode
End sub
It's MSXML2.IXMLDOMNodeList, not MSXML.IXMLDOMNodeList.
The library may be missing from your references. Try this.
Manually adding MSXML2
1. Open MS Access.
2. Database Tools ribbon
3. Visual Basic ribbon item (icon)
4. Double-click on any module to open it.
5. Tools menu
6. References…
7. Find Microsoft XML, v6.0. is in the list
a. If in list but not checked, check it and click [OK].
b. If not in the list:
i. click [Browse…] and add "c:\windows\system32\msxml6.dll"
8. [OK] your way back to the Visual Basic window.
9. Close the Visual Basic Window. You should be good to go.
Programmatically adding MSXML2
Add the following sub and function. Run the sub. Edit the sub to include a path if necessary.
Check for broken references in the library
Adapted from Add references programatically
Sub CheckXmlLibrary()
' This refers to your VBA project.
Dim chkRef As Reference, RetVal As Integer ' A reference.
Dim foundWord As Boolean, foundExcel As Boolean, foundXml As Boolean
foundWord = False
foundExcel = False
foundXml = False
' Check through the selected references in the References dialog box.
For Each chkRef In References
' If the reference is broken, send the name to the Immediate Window.
If chkRef.IsBroken Then
Debug.Print chkRef.Name
End If
'copy and repeat the next 2 if statements as needed for additional libraries.
If InStr(UCase(chkRef.FullPath), UCase("msxml6.dll")) <> 0 Then
foundXml = True
End If
Next
If (foundXml = False) Then
'References.AddFromFile ("C:\Windows\System32\msxml6.dll") <-- For other than XML, modify this line and comment out line below.
RetVal = AddMsXmlLibrary
If RetVal = 0 Then MsgBox "Failed to load XML Library (msxml6.dll). XML upload/download will not work."
End If
End Sub
Add XML reference to the library
Developed by Chris Advena. Thanks to http://allenbrowne.com/ser-38.html for the insight.
Public Function AddMsXmlLibrary(Optional PathFileExtStr As String = "C:\Windows\System32\msxml6.dll") As Integer
On Error GoTo FoundError
AddMsXmlLibrary = 1
References.AddFromFile (PathFileExtStr)
AllDone:
Exit Function
FoundError:
On Error Resume Next
AddMsXmlLibrary = 0
On Error GoTo 0
End Function

How do I display an image from Sql Server with Microsoft Access?

I upsized an Access 2007 database to SQL Server 2008 R2. The images are in SQL Server as image type. Access has link to the table containing the image. When I try to display from within Access, it won't do it. It still has the OLE Object wrapper.
How can I get that image and display it on my forms in Access? I do not have the option, at the moment, to remove the images, put them in a directory and point to them (the best way I know but not an option). I need to read the image / blob file directly from SQL Server and display it on an Access form.
Thank you for any ideas.
I saw this but it did not help:
How to display image from sql server in ms access
http://access.bukrek.net/documentation looks like the file in folder method
Since Access 2010, you can use the PictureData property to store and display images from SQL Server. You will need a bound control for an SQL Server data type varbinary(max), which can be hidden, and an unbound Image control in MS Access. You can now simply say:
Private Sub Form_Current()
Me.MSAccessImageControl.PictureData = Me.SQLServerImage
End Sub
And vice versa. You will need to add some error management to that, but very little else.
Below is a function I have successfully used called BlobToFile. And I also posted the code that I use to test it. The picture gets dumped to a so-called temp file but its not truly temp because it isn't in the temp directory. You can manually delete the image file or else you'll have to write it to your temp folder instead. Then I have an image control where I display the picture.
Private Sub Command1_Click()
Dim r As DAO.Recordset, sSQL As String, sTempPicture As String
sSQL = "SELECT ID, PictureBlobField FROM MyTable"
Set r = CurrentDb.OpenRecordset(sSQL, dbSeeChanges)
If Not (r.EOF And r.BOF) Then
sTempPicture = "C:\MyTempPicture.jpg"
Call BlobToFile(sTempPicture, r("PictureBlobField"))
If Dir(sTempPicture) <> "" Then
Me.imagecontrol1.Picture = sTempPicture
End If
End If
r.Close
Set r = Nothing
End Sub
'Function: BlobToFile - Extracts the data in a binary field to a disk file.
'Parameter: strFile - Full path and filename of the destination file.
'Parameter: Field - The field containing the blob.
'Return: The length of the data extracted.
Public Function BlobToFile(strFile As String, ByRef Field As Object) As Long
On Error GoTo BlobToFileError
Dim nFileNum As Integer
Dim abytData() As Byte
BlobToFile = 0
nFileNum = FreeFile
Open strFile For Binary Access Write As nFileNum
abytData = Field
Put #nFileNum, , abytData
BlobToFile = LOF(nFileNum)
BlobToFileExit:
If nFileNum > 0 Then Close nFileNum
Exit Function
BlobToFileError:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, _
"Error writing file in BlobToFile"
BlobToFile = 0
Resume BlobToFileExit
End Function

Migrate Web Services (VS2003) to WCF (VS2010)

Our site is maintained with VS2003. We converted our solution to VS2010--it is a Web Application Project. It has several Web Services files (.asmx file endings) that we hoped to convert to WCF in two stages, first preserve the function of the asmx files that write back XML documents via AJAX to the client..., and then learn to build AJAX-enabled WCF Services to do the same things.
We have researched the 'Could not create type xxx'-error and the advice varies. We're certain(!!) that having an App_Code folder is not the difference, and that we've named our namespace and class correctly, and that we've decorated the Web Service code correctly, and that we're able to use ASP.Net 2.0 to activate these services, and that we have the application level set correctly in IIS... and we're still not able to get past the error.
Here is our asmx code (we created a test page with ScriptManager control to try to hit this one Web Method, but we never got past the build for the service). You certainly don't need to bother with the actual database pulls, but I left them in anyway:
Imports System
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Web.Script.Services
Imports System.ComponentModel
Imports System.Data.SqlClient
Imports System.Text
Imports System.Uri
Imports System.Xml
Imports System.IO
<WebService([Namespace]:="nsCarousel", Description:="Carousel Web Service Methods")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
Public Class Carousel
Inherits WebService
<WebMethod(Description:="Get Dealer Info")> _
Public Function GetDealerInfo(ByVal DID%) As String
Dim s$, sql$, sRequest$, sRequestPathQuery$, sDID$, sAJAX$, sReturn$, sIP$, sWebSite$, sErr$, sDealerSearch$
Dim sXML$, sXMLDealerResults$, sXMLPath$
Dim sUserName$, sGeneralDesc$, sStatusText$
Dim bPost As Boolean
Dim bHaveData As Boolean
Dim ds As DataSet
Dim dasql As SqlDataAdapter
Dim sqldr As SqlDataReader
Dim sqlConn As SqlConnection
Dim sqlCmd As SqlCommand
Dim xdoc As New XmlDocument
Dim xnode As XmlNode
Dim xrefnode As XmlNode
Dim xnewnode As XmlElement
Try
'/ need test of sRequest for reference and use in test just below
bPost = False
sDID = Convert.ToString(DID)
sGeneralDesc = "Dealer Pull"
sqlConn = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionStringLong"))
sqlConn.Open()
'/ new sp to preserve nodes, even when fields are null
'/ get results for individual dealer
sql = "insert into junk(entrydate, sql_stmts) select GetDate(), '" & sDID & "';"
sqlCmd = New SqlCommand(sql, sqlConn)
sqlCmd.ExecuteNonQuery()
sqlCmd.Dispose()
sql = "Select_DRPROByDID_xml " & sDID
sqlCmd = New SqlCommand(sql, sqlConn)
sqldr = sqlCmd.ExecuteReader()
'/ quick test if have data
bHaveData = False
Do While sqldr.Read
If Not (IsDBNull(sqldr("DNum"))) Then
bHaveData = True
End If
Exit Do
Loop
sqldr.Close()
sqldr = Nothing
sqlCmd.Dispose()
sqlCmd = Nothing
'/ s will include a node for NewDataSet -> remove and add nodes for msg based on status
'/ and DealerError
If bHaveData Then
dasql = New SqlDataAdapter(sql, sqlConn)
ds = New DataSet
dasql.Fill(ds)
s = ds.GetXml
sXMLDealerResults = s
dasql.Dispose()
ds.Clear()
dasql = Nothing
ds = Nothing
'/ query the XML doc
xdoc.LoadXml(s)
xnode = xdoc.SelectSingleNode("/NewDataSet/Table")
If (xnode.HasChildNodes) Then
If (sDID.Length > 0) Then
sStatusText = xdoc.GetElementsByTagName("DRStat").Item(0).InnerText
Select Case sStatusText
Case "A"
'/ test next when opportunity exists
'/ set current node at Table
'sXMLPath = "/NewDataSet/Table"
'/ set Table as the current node
'xrefnode = xdoc.SelectSingleNode(sXMLPath)
'xnewnode = xdoc.CreateElement("DealerMsg")
'sStatusText = "Active dealer found."
'xdoc.InsertAfter(xnewnode, xrefnode)
sXMLDealerResults = sXMLDealerResults.Replace("<Table>", "<Table><DealerMsg>Active dealer found.</DealerMsg>")
Case "C"
sXMLDealerResults = sXMLDealerResults.Replace("<Table>", "<Table><DealerMsg>Dealer has been cancelled.</DealerMsg>")
Case "H"
sXMLDealerResults = sXMLDealerResults.Replace("<Table>", "<Table><DealerMsg>Dealer is on hold.</DealerMsg>")
Case Else
sXMLDealerResults = sXMLDealerResults.Replace("<Table>", "<Table><DealerMsg>Dealer status is invalid.</DealerMsg>")
End Select
sXMLDealerResults = sXMLDealerResults.Replace("<Table>", "<Table><DealerError>1</DealerError>")
Else
'/ do nothing
End If
Else
sXMLDealerResults = sXMLDealerResults.Replace("<Table>", "<Table><DealerError>0</DealerError><DealerMsg>Dealer not found.</DealerMsg>")
End If
Else
sXMLDealerResults = "<Table><DealerError>0</DealerError><DealerMsg>Dealer not found.</DealerMsg></Table>"
End If
sXMLDealerResults = sXMLDealerResults.Replace("<NewDataSet>", "")
sXMLDealerResults = sXMLDealerResults.Replace("</NewDataSet>", "")
If (sDID.Length > 0) Then
sXMLDealerResults = sXMLDealerResults.Replace("<Table>", "")
sXMLDealerResults = sXMLDealerResults.Replace("</Table>", "")
Else
sXMLDealerResults = sXMLDealerResults.Replace("<Table>", "<Dealer>")
sXMLDealerResults = sXMLDealerResults.Replace("</Table>", "</Dealer>")
End If
sXML = "<?xml version=""1.0"" ?><DealerFetch>" + sXMLDealerResults.Trim + "</DealerFetch>"
'If sReturn.Trim.Length = 0 Then
' Response.ContentType = "text/xml"
' Response.Write(sXML)
'End If
sqlConn.Close()
sqlConn = Nothing
Return sXML
Catch exp As Exception
sErr = sErr & " " & exp.Message.ToString
End Try
End Function
End Class
Any help would be appreciated. Maybe it's something obvious that will appear to someone here quickly, but it sure is making us fret!!! If you need more info or code, please let us know.
There are tons of good samples and demos how to achieve this.......
Just a few a quick Google search turned up:
Convert existing asmx .net web service to WCF service in .net 3.0/3.5
Convert .asmx file to WCF .svc file to create simple API web service
Migrating a Versionable ASMX Web Service to WCF
I would just search Google for your keywords (ASMX, WCF, Migrate) and you should get tons of links and useful resources.....
As for resources to learn the basics of WCF: there's the MSDN WCF Developer Center which has everything from beginner's tutorials to articles and sample code.
Also, check out the screen cast library up on MSDN for some really useful, 10-15 minute chunks of information on just about any topic related to WCF you might be interested in.

Resources