tags:

views:

79

answers:

2

I’m trying to import a table into a secured sql database using vb.net but it seems to timeout (or so I think) and not import properly (null value), I truncate the table to save the field types and then call the shell() function to import the file and

'Clean out the existing data in the validation import table

cmd.CommandText = "TRUNCATE TABLE HedgeFileBuilders.dbo.HedgeInput_" & strProduct & "_VALIDATOR;"
cmd.ExecuteNonQuery()

're-import the inforce file to validate it

Try
    If chkSQLServerSource Then
    Shell(SQLLOCALDIR & "Prog\bcp.exe FileBuilders.dbo.Input_" & strProduct   & "_VALIDATOR in " & strFileName & "  -c -t , -r \n -S server -U user -P passkey -F 2 -h TABLOCK", AppWinStyle.Hide, True)
    Else
    Shell(SQLLOCALDIR & "Prog\bcp.exe FileBuilders.dbo.Input_" & strProduct & "_VALIDATOR in " & strFileName & "  -c -t , -r \n -S pcname -T -F 2 -h TABLOCK", AppWinStyle.Hide, True)
    End If
Catch ex As Exception
    MessageBox.Show("ERROR: An error occurred while re-importing the new business file.  Contact the system administrator.  " & ex.Message, "Contact System Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error)
    Exit Sub
End Try

'THIS DOESN'T Return and Error but null results. I do the import manually in SQL and it works (all the data is there). I even use the strFilename and Table name indicated above from vb code to make sure I didn't get the names wrong when importing manually.

What am I doing wrong?

P.S. I tried the timeout integer parameter '-l', after the boolean 'True' above and it did not help.

A: 

I suggest comparing your string (build it in a local variable) you are executing to the similar string from a known good working batch/cmd file.

Also, if your directory for bcp.exe has spaces, you will need to use double-quotes around the entire executable path in your string. Similarly for the strFilename.

Basically, verify that your known good manual command-line import for the same file is being produced in your code.

Cade Roux
A: 

The datatypes in the table i was trying to import are different than the SQL table that was being truncated and adding the imported data (null and not nulls, etc) I fixed the datatypes to match and the shell command line works as expected.