473,395 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Data file uploaded but bulk insert isnt working

347 100+
I have the following code:

Expand|Select|Wrap|Line Numbers
  1. Imports System.IO
  2. Imports System.Data
  3. Imports System.Data.SqlClient
  4. Partial Class _Default
  5.     Inherits System.Web.UI.Page
  6.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  7.  
  8.     End Sub
  9.     Protected Sub Submit1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  10.         Dim SaveLocation = "\\MSBWEB3\wwwroot\Webfile1\Reminders\Doug_Ancil\upload.txt"
  11.         If UploadFile(SaveLocation) Then
  12.             'the file was uploaded: now try saving it to the database
  13.             SaveToDatabase(SaveLocation)
  14.         End If
  15.     End Sub
  16.     Private Function UploadFile(ByVal SavePath As String) As Boolean
  17.         Dim fileWasUploaded As Boolean = False 'indicates whether or not the file was uploaded
  18.  
  19.         'Checking if the file upload control contains a file
  20.         If Not File1.PostedFile Is Nothing And File1.PostedFile.ContentLength > 0 Then
  21.             Try
  22.                 'checking if it was .txt file BEFORE UPLOADING IT!
  23.                 'You used to upload it first...but the file could be a virus
  24.                 If File1.FileName.EndsWith(".txt") = False Then
  25.                     'The file is not the expected type...do not upload it
  26.                     'just post the validation message
  27.                     message.Text = "The file you submitted is not a .txt file, please select a .txt file to upload."
  28.                 Else
  29.                     'The file is a .txt file
  30.                     'checking to see if the file exists already
  31.                     'If it does exist Deleting the existing one so that the new one can be created
  32.                     If IO.File.Exists(SavePath) Then
  33.                         IO.File.Delete(SavePath)
  34.                     End If
  35.  
  36.                     'Now upload the file (save it to your server)
  37.                     File1.PostedFile.SaveAs(SavePath)
  38.  
  39.                     'After saving it check to see if it exists
  40.                     If File.Exists(SavePath) Then
  41.                         'Upload was sucessful
  42.                         message.Text = "Thank you for your submission"
  43.                         fileWasUploaded = True
  44.                     Else
  45.                         'the file was not saved
  46.                         message.Text = "Unable to save the file"
  47.                     End If
  48.                 End If
  49.  
  50.             Catch Exc As Exception
  51.                 'We encountered a problem
  52.                 message.Text = Exc.Message + " " + Exc.StackTrace
  53.             End Try
  54.         Else
  55.             'No file was selected for uploading
  56.             message.Text = "Please select a file to upload"
  57.         End If
  58.         Return fileWasUploaded
  59.     End Function
  60.  
  61.     Private Sub SaveToDatabase(ByVal SavePath As String)
  62.         Try
  63.             Dim sqlQueryText As String = _
  64.               "BULK INSERT dialerresults " + _
  65.               "FROM '" & SavePath & "' " + _
  66.               "WITH ( FIELDTERMINATOR = ',' , ROWTERMINATOR = '\n' )"
  67.  
  68.  
  69.             ' and bulk import the data:   
  70.             'If ConfigurationManager.ConnectionStrings("Dialerresults") IsNot Nothing Then
  71.             'Dim connection As String = ConfigurationManager.ConnectionStrings("Dialerresults").ConnectionString
  72.             Dim connection As String = "data source=10.2.1.40;initial catalog=IVRDialer;uid=xxx;password=xxxx;"
  73.  
  74.             Using con As New SqlConnection(connection)
  75.                 con.Open()
  76.                 ' execute the bulk import   
  77.                 Using cmd As New SqlCommand(sqlQueryText, con)
  78.  
  79.                     cmd.ExecuteNonQuery()
  80.  
  81.                 End Using
  82.             End Using
  83.  
  84.             'Else
  85.             'message.Text="ConfigurationManager.ConnectionStrings('Dialerresults') is Nothing!"
  86.             'End If
  87.         Catch ex As Exception
  88.             message.Text = ex.Message + " " + ex.StackTrace
  89.  
  90.         End Try
  91.     End Sub
  92.  
  93. End Class
  94.  
What's happening is when I try to upload a file, it tells me that everything is fine but when I look in my database, there is no data there. What am I missing? This worked before but we had to move this to another directory on the server and after we did that, the bulk insert function seems to be broken, though the server isn't returning any kinds of errors.

Any help would be appreciated.

Thank you,

Doug
Jun 28 '10 #1
1 2357
dougancil
347 100+
@dougancil
This seems to be working now. I have no idea why it wasnt working but it seems to be just fine.

Thank you

Doug
Jun 28 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: php newbie | last post by:
Hello, I have been trying to load a delimited data file to SQL Server. I have tried both of the options that are available: each time, I get different errors. This is on an eval version of SQL...
6
by: pk | last post by:
Sorry for the piece-by-piece nature of this post, I moved it from a dormant group to this one and it was 3 separate posts in the other group. Anyway... I'm trying to bulk insert a text file of...
2
by: Mike Husler | last post by:
We have created CSV files on HPUX 11.0 and transferred them via ASCII ftp to our SQL Server machine file store to load large amounts for data using the BULK INSERT command. This is the command: ...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
2
by: Ted | last post by:
I have BULK INSERT T-SQL statements that work for all of my basic data tables except for one. Here is the problem statement (with obvious replacement of irrelevant path info): BULK INSERT...
1
by: planetmatt | last post by:
I need to create a page that bulk inserts a CSV text file into SQL Server. I have plenty of experience with SQL Server and have built some web apps with classic ASP but have never used ASP.NET...
3
by: Tim Satterwhite | last post by:
Hi All, I think this is a thorny problem, and I'm hoping you can help. I've not found this exact issue described anywhere yet. I have a stored procedure that calls BULK INSERT on a set of...
0
by: teddymeu | last post by:
Hi Guys, since I've done nothing but ask questions these last few weeks to get my first application up and running I thought it was about time to share the wealth and help out a newbie like me since...
2
by: fperri | last post by:
I am using SQL Server 2005 and SQL Server Management Studio Express. I'm new to stored procedures and I was creating this one to test out the BULK INSERT sql command. When I execute it says...
1
by: dougancil | last post by:
I have a web page written in asp.net that is basically an upload button that does a bulk insert into a sql table. When a user presses an upload button, a .txt file is uploaded to a directory on...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.