Saturday, February 11, 2012

(urgent)help needed with this error message

Hi i am trying to transfer the contents of a dbf file to sql server 2005 and this is my error message

'C:\Documents and Settings\Karen\My Documents\Visual Studio 2005\WebSites\ASC1\pdf\client\AS.DBF' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.

This is my code

If (FlAS.PostedFile.FileName.ToLower.EndsWith(".dbf"))Then FlAS.PostedFile.SaveAs(location) Try'Connection string to a dbase file Dim dbfConnectionString As String = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source ={0};Extended Properties= dBase IV", location) 'create connectionto the DBFfile Using connectionAs Data.OleDb.OleDbConnection = New Data.OleDb.OleDbConnection(dbfConnectionString) Dim commandAs Data.OleDb.OleDbCommand = New Data.OleDb.OleDbCommand("Select *from AS.DBF", connection) connection.Open()'Create a dbDatareader to the dbf file Using dr As Data.Common.DbDataReader = command.ExecuteReader() Dim sqlConnectionString As String = System.Configuration.ConfigurationManager.AppSettings(APPSETTINGS_CONNECTION) Dim myConnection As New SqlConnection(System.Configuration.ConfigurationManager.AppSettings(APPSETTINGS_CONNECTION)) Dim query As String = "Truncate table ASDBF" myConnection.Open() Dim cmd As New SqlCommand(query, myConnection) cmd.CommandType = CommandType.Text cmd.ExecuteScalar() myConnection.Close() 'bulk copyof sql server Using BulkCopyAs SqlBulkCopy = New SqlBulkCopy(sqlConnectionString) BulkCopy.DestinationTableName = "ASDBF" BulkCopy.WriteToServer(dr)End UsingEnd Using connection.Close()End Using Catch exAs Exception Throw exEnd TryEnd If

Any help will be appreciated.

Regards

Karen

What is the "location" variable? What is it's value? Where is it set?

|||

location is set before the if Statement and its a string

location = Server.MapPath("pdf/client/" + Session("ClientName") + strAS)

|||

Debug your code and verify that the string "location" looks as you would expect

|||

yeah it does... but how would i know if i have to use a foxpro connection string or a dbase connection string and which version?

Regards

Karen

|||

Where is your code failing? On file.saveas(...)?

|||no its failing at

connection.Open() ... cause i can see the file name in the location that i am saving it to.

|||

Using 'Tools' --> 'Connect to Database', try to create a connection to the .DBF file. I think that there is a problem with the connection string. Once you successfully connect from Visual Studio, you should be able to copy that connection string into your code.

|||

I found this article.. Hopefully this will help you. Looks like you may need to leave the filename off of the Data Source (only include the folder name).. Take a look

http://www.msdner.com/forum/thread51916.html

|||

thanks should i use this provider?

Microsoft Jet 4.0 OLE DB Provider or which one?

|||

Just a quick glance through the article, it looked like your connection string was ok, except for the filename on the end of the datasource.

|||

i used the same connection string to a excel file but specified the extended properties as excel 8.0 and it works fine... but not sure why isnt it working for a dbf file

|||

Thanks SSWanner for your answer... I got it working... I downloaded the fox pro oledb provider... and it kinda worked good it failed at the sql insertion (sql exception) and i am familiar with that error. The error i got is

Received an invalid column length from the bcp client for colid 1

I just need to change the column length in sql server..

Again Thanks a lot.

Regards

Karen

No comments:

Post a Comment