Error with file datasource for querying

In a ssis package I have the following line of code in my scsript task:

 cnnCSV.ConnectionString = "Driver={Microsoft Text Driver (*.txt; *.csv)}; " & _
                                        "Dbq=" & pstrPath & ";" & _
                                       "Extensions=asc,csv,tab,txt;"

 cnnCSV.Open()

Is is throwing the error:

[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

The path it is attempting to open is a unc path and I am wondering if that is the problem.
UnderSevenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

unknown_routineCommented:
Are you trying to read a CSV file?

Where is CSV file located?


You can read the CSV file simply using below:

For Each line As String In System.IO.File.ReadAllLines("C:\Myfile.csv")
   'Do some stuff
   '''''''''''''''''''''''''''''
Next

Open in new window

0
UnderSevenAuthor Commented:
It is a csv file.  I'm trying not to alter the original code as much as possible.  The reason it seems to be written that way is so that it could later do this:

Dim cmdCSV As New OdbcCommand("SELECT * FROM [" & pstrFileName & "]", cnnCSV)
        Dim drCSV As OdbcDataReader = cmdCSV.ExecuteReader


Dim dtRemittanceRecords As New DataTable("Remittances")
        dtRemittanceRecords.Columns.Add("RecordIndicator", Type.GetType("System.String"))
        dtRemittanceRecords.Columns.Add("TransactionConfirmationID", Type.GetType("System.String"))

Do While drCSV.Read()
            If (Not (IsDBNull(drCSV.GetValue(0)))) Then
                If (drCSV.GetValue(0) = "D") Then
                    Dim newRemittanceRecordRow As DataRow = dtRemittanceRecords.NewRow()
                    newRemittanceRecordRow("RecordIndicator") = drCSV.GetValue(0)
                    newRemittanceRecordRow("TransactionConfirmationID") = drCSV.GetValue(1)


File is located: \\city\shared\filesforproc\
0
unknown_routineCommented:
Using Odbc for reading a simple CSV file is overkill.  When seeing your question I thought the file is embeded inside a table in SQL server.


If file is in a physical folder such as File is located: \\city\shared\filesforproc\

Just get it simply by :

For Each line As String In System.IO.File.ReadAllLines(@"\\city\shared\filesforproc\")
   'Do some stuff
   '''''''''''''''''''''''''''''
Next



I suggest at minimum try to test the above code to see if you have access to that path.
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

UnderSevenAuthor Commented:
I see where you are going, is there a way I could use not a string though, so as to load the lines in similarly to as if they were rows in a table?  I'd like to keep this code relatively unchanged:

 Dim newRemittanceRecordRow As DataRow = dtRemittanceRecords.NewRow()
                    newRemittanceRecordRow("RecordIndicator") = drCSV.GetValue(0)
                    newRemittanceRecordRow("TransactionConfirmationID") = drCSV.GetValue(1)
0
unknown_routineCommented:
If you are using a CSV then lines should be delimited by a character.

You can use VB.NET split function to break the line into fields.


for example:
For Each line As String In System.IO.File.ReadAllLines(@"\\city\shared\filesforproc\")
  
[indent]Dim arrDataRow() as string=line.Split('|")     'assuming CSV is '|' delimited
 
Dim newRemittanceRecordRow As DataRow = dtRemittanceRecords.NewRow()
                    newRemittanceRecordRow("RecordIndicator") = line(0)
                    newRemittanceRecordRow("TransactionConfirmationID") = line(1)[/indent]

 
Next 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
UnderSevenAuthor Commented:
Thanks, there are a lot of columns in that file so preserving as much as the original code really helps me with not having to re-write too much.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.