Reading CSV File With OLEDB Ignores First Line Even With HDR=No In Connection String?

Jan 4, 2011

We're converting a Classic ASP site to an ASP.NET site. One function was to upload a 'template' of data in CSV format for importing into the database. There were several different record types in there (the first field always indentifies the type of data).

The task was to get the CSV into a DataTable so it could be validated (new project is to have MUCH better validation rules)

The code seemed pretty straightforward - watered down (taking out comments, Try/Catch, etc) it is as follows:

Dim da As New System.Data.OleDb.OleDbDataAdapter
Dim cn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDirectory & ";" & "Extended Properties=""Text;HDR=No;FMT=Delimited;""")
Dim cd As New System.Data.OleDb.OleDbCommand("SELECT * FROM " & strCSVFilename, cn)
cn.Open()
da.SelectCommand = cd
da.Fill(dtData)

The DataTable (dtData) is populated, but only starting with the second line of the CSV file DESPITE the fact that "HDR=No" is in the connection string. What am I missing here?

View 1 Replies


Similar Messages:

Pros/cons Of Reading Connection String From Physical File Versus Application Object

Apr 9, 2010

my ASP.NET application reads an xml file to determine which environment it's currently in (e.g. local, development, production).

It checks this file every single time it opens a connection to the database, in order to know which connection string to grab from the Application Settings.

I'm entering a phase of development where efficiency is becoming a concern. I don't think it's a good idea to have to read a file on a physical disk ever single time I wish to access the database (very often).

I was considering storing the connection string in Application["ConnectionString"].

[code].....

I didn't design the application so I figure there must have been a reason for reading the xml file every time (to change settings while the application runs?) I have very little concept of the inner workings here. What are the pros and cons?

View 2 Replies

VS 2008 OleDb Connection String In Web.Config

Aug 14, 2010

How to put an OleDB Connection String in Web.Config I wrote the following code but getting error

Code:
<appSettings>
<add key="ConnectionString"
value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("~/App_Data/AMS.MDB")" />
</appSettings>

Getting error while concatenating a string Data Source=" & Server.MapPath

View 4 Replies

Reading A File Into Memory And Then Reading It One Line At A Time?

Mar 7, 2011

I know this is probably a pretty easy thing to do and it is if I can upload the file and store it onto the hard drive of the server. What I need to do is read the text file into memory and then parse through it one line at a time. Anyone have any code that demonstrates that?

View 8 Replies

Web Forms :: Read CSV File Without Using Oledb Connection?

May 24, 2012

How can i read CSV file without using Oledb connection.

View 1 Replies

Connection String Reading Data From Excel?

May 18, 2010

I am trying to read data from excel file in asp.net. I have added the connection string to webConfig file:

<add name="xls" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=HPM_DB.xls;Extended Properties=Excel 8.0"/>

But it shows me an errormessage when I run this query:

string query = "Select * from [IO_Definition$]";

IO_Definition is the name of the spreadsheet in my excel file. I also added the excel file to the App_Data folder of the website.

The error is:

The Microsoft Jet database engine could not find the object 'IO_Definition$'. Make sure the object exists and that you spell its name and the path name correctly.

The thing is, when I write the absolute path of the excel file in the connectionString it does work. Is there anyway I can make it work without writing the absolute path?

View 1 Replies

DataSource Controls :: Oledb Connection String Exception - "Unspecified Error"

May 5, 2010

I am developing one web application using MS Access database using oledb connection.Previously i checked the same application is works well in the same machine.Now Today i checked they provide "Unspecified Error". And also Provide the following Exception:

System.Data.OleDb.OleDbException: Unspecified errorat System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.OleDb.OleDbConnection.Open() at clsOledbClass.opencon() in c:inetpubwwwrootcheckNPCApp_CodeclsOledbClass.cs:line 64

I am using the following connection string for connecting database:

[Code]....

View 1 Replies

Web Forms :: How To Access Connection Connection String From Sub Folder Web.config File

Mar 15, 2011

just for my testing purpose i know i can define both the connection's outside in a single web config file by different name's and access them in my front end according to it but what if i want to have seprate for both connection's web.config situation is like this see image so i want to access my connections from second web config file how i can do that.

[Code]...

i tired this but its giving error

[Code]....

View 1 Replies

Web Forms :: Reading Text File Into Multi-line Text Box

Oct 12, 2010

I have an input type, so a text box which has a browse button next to it. When it is clicked, the file that is selected has it's full path placed into the text box.

<input type="file" runat="server" id="txtFilename" style="width:400px" />

Where is the event!

Now that I have the path to the file in the textbox of the input type, I want to load each line of this file into a textbox that is able to handle multiline text.

I don't want the file to be uploaded to the website. I just want to contents of the file read and placed in a textbox all with one click on the browse button.

View 1 Replies

How Oledb Connection Should Be Declared

Sep 27, 2010

I m new in asp.net c#.

How to declare a oledbconnection object in asp.net c#.

Means should it be declared as a static or public?

ex:- suppose the object is OleDbConnection con;

Whether it should be static OleDbConnection con;

Or public OleDbConnection con;

View 7 Replies

DataSource Controls :: OLEDB Connection

May 27, 2010

The attached code, the oledb part, is giving me a blank web page saying it cant connect on my local dev server. I have another app with the same code, in fact I copied it and changed the db names. The one I copied from works fine.

[Code]....

View 5 Replies

Databases :: Connection Timeout In OLEDB?

Jan 20, 2011

I need to set connection timeout in oledb connection string like

stringA= "Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=sa;PWD=password;Initial Catalog=DB;Data Source=127.0.0.1;Connect
Timeout=30" [code]....

View 2 Replies

Provider Connection String Of Entity Framework Be Substituted With A DB Connection String Already Defined In Web.config?

Feb 2, 2011

I have a db connection string 'ApplicationServices' defined in the connectionString section of web.config and 3 Entity Framework connection strings which have the provider connection string attribute with the same connection string as the one in 'ApplicationServices'. Is there a way to reference connectionString in 'ApplicationServices' for the provider connection string attribute of the EF connection string in the web.config, rather than providing the connection string all over again?

View 1 Replies

DataSource Controls :: Difference Between Oledb And Odbc Connection?

Jun 23, 2010

i am using my sql database. what type of data connection improve the performance.oledb connection or odbc connection ? what is the theory of these architectures?

View 8 Replies

Importing CSV File Using VB - Unable To Split Line String Correctly

Jul 28, 2010

I am trying to import a csv file but unable to split the line string correctly.

DIM fields() as String = line.split(",")

Where the sample data is as below

1,"khdaf",2,"hello,world,hi","2154",5412
1,"khdaf",3,"hello,hi","2154",5412

Issue is that when i split first line it gives me array of eight(08) whereas actual columns are six (06)

View 8 Replies

Web Forms :: Read Excel Files In Pure C# Without Using OleDB Connection

May 23, 2012

I am Importing an excel file using oledb connection in asp.net.

but it is not working on server.

now i want to read excel file without interop.

How can i do it.

View 1 Replies

C# - Get The Connection String Value From Hibernate.cfg.xml File?

Mar 12, 2010

I'm using Fluent NHibernate and need to get my Connection String from the connection.connection_string property on hibernate.cfg.xml file to create my Session Factory:

private static ISessionFactory SessionFactory {
get {
return = Fluently.Configure()
.Database(MySQLConfiguration.Standard.ConnectionString(c => c.FromConnectionStringWithKey("MyConnStr")))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<FooMap>())
.ExposeConfiguration(c => c.Properties.Add("hbm2ddl.keywords", "none"))
.BuildSessionFactory();
}
}

I want to replace MyConnStr (that is in my web.config file) "c => c.FromConnectionStringWithKey("MyConnStr")" for the connection string from the hibernate.cfg.xml file.

I've tried use NHibernate.Cfg.Environment.ConnectionString, but it didn't work.

View 2 Replies

Reading An Excel Work Book - OLEDB Or Excel Interop

Mar 22, 2011

I need to read an Excel work book with 2 sheet which have more than 60,000 records. The application is an ASP.Net application so the performance matters.

Which approach should I take? Sohuld I do it using Microsoft.Office.Interop.Excel or should I do it using OLEDB in ADO.Net?

View 3 Replies

How To Write Connection String In Web.config File

Jul 30, 2010

how to write connection string in app.config file in vb.net windows application and how to call connection string in forms

View 2 Replies

Finding About Connection String In Web.config File

Jan 15, 2010

why we use connection string in web.config file??? Or what is the benefit of using connection string in web.config file?

View 7 Replies

SQL Server :: Connection String In Config File?

Aug 6, 2010

I am having trouble connecting to a ms sql database on the server. The hosting company said that the .sql file was imported successfully, but when I try to use the 'login' or 'create account' features im getting an error page saying:

Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. make sure the user has a local user profile on the computer. The connection will be closed.

I am sure all the connection info is correct so it is really frustrating trying to work the problem. I have listed the connection string in my web.config file to see if anyone can see anything wrong with it.

View 4 Replies

Calling Connection String From Webconfig File?

Jun 9, 2010

I'm using Visual Studio 2008 and SQL Server 2008 Developer to create a website.

I'm trying to test a connectino to a local database in my computer.

What I did is create a connection string in the webconfig file like this:

[Code]....

Then I want to call that connection string like this in the default.aspx.cs file I write the following code:

[Code]....

I'm not getting any error or warning in any of the code but when I run the page I throws me an error telling me:

The connectionstring property has not been initialized.

If I run with debug on it shows this:

[Code]....

Line 22 in red.

I don't know what I'm doing wrong since VIsual Studio does not tell me there is an error, it just seems like it cannot make the connection.

View 4 Replies

Configuration :: Connection String For .DBF File Don't Work When Using IIS

Sep 17, 2010

I am using this connection string to query some .DBF .

[Code]....

How can i make it work?

View 1 Replies

Configuration :: Connection String In Web Config File?

Feb 3, 2011

I have this in the web config file <connectionstrings> section. Why is there an add and then remove and then again an add...what is it trying to accomplish here? and in the second code section, I use that string in a sqldatasource control. Second question: Can I just use the name attribute value "localsqlserver" form web config file, in place of the connection string in the data source? is it why that attribute is for?

[Code]....

View 2 Replies

How To Specify Metadata Location In Connection String When Using An Edmx File

Jan 29, 2010

I have a web project with a data model defined in an edmx file. The connection string starts like this:

metadata=res://*/;

This has worked fine for a while. But somebody else working on the project created a dll that also uses the entity framework and added it to the bin folder. Now when I try to create my connection there is an error loading the metadata.

Aside from totally changing the way one or both of us is doing things, I wonder if the problem can be fixed if my connection string can be changed to only look for the metadata defined in my edmx file. The problem is, for the life of me I can't find the right syntax to do this. The metadata is embedded in the output assembly, so there are no physical metadata files to point to. How exactly should I specify the metadata location in the connection string?

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved