Showing posts with label oledbconnection. Show all posts
Showing posts with label oledbconnection. Show all posts

Wednesday, March 21, 2012

OleDbConnection with MSDE

I'm trying to connect to a MSDE database using the following code:


'set up connection
dim myConnection as new OleDbConnection("Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=LearnASP_DB;Integrated Security=SSPI;Connect Timeout=30")

'open connection
dim myCommand as new OleDbDataAdapter("select * from tblUsers",myConnection)

'fill dataset
dim ds as DataSet = new DataSet()
myCommand.Fill(ds, "tblUsers")

And I'm getting the following error:

[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.

Can someone tell me what I'm doing wrong?

Thanks in advanceI am pretty sure you should use (local) instead of localhost for the Data Source.

Terri|||localhost calls the webserver. (local) is the correct syntax.

should also add that if you're using "Provider=SQLOLEDB;", you might as well use System.Data.SqlClient|||you said if I'm using Provider="SQLOLEDB" I migh as well use System.Data.SqlClient

What are my other choices for Provider?
And what the difference between OleDbConnection and SqlClient?

Thanks again|||SqlClient was made specifically as the namespace to use for SqlServer. No "Provider" is needed.

http://able-consulting.com/dotnet/adonet/Data_Providers.htm#SQLClientManagedProvider|||thanks for you help :)

OleDbConnection vs SqlConnection

Hi,

How much of a performance difference is there between connecting to SQL Server 2000 using OleDbConnection or using SqlConnection?

The reason I'm asking is I am taking on the task of updating an older program that uses a Access Database to use SQL Server, but it has a Database Utility class that uses OleDbConnection. I'm just debating whether it would be worthwhile to upgrade the class to use the SQL objects rather than Oledb. Program does a lot of update and insert of invidual records, and a few select statements that usually return from 1 to 2000 records up to a maximum of 50,000 records

ThanksConsider this:

OleDb is a wrapper for all the native drivers, combined so that one interface may be used for any... OleDb ends up applying datatype conversions, etc, and communicates those conversions to SQL

The native sql client drivers do not have to go through this wrapper interface. They are SQL-ready.

I don't know about specific benchmarks, but this simple observation keeps me from using it when I know I'm accessing a SQL database.

However, the .NET framework allows you to abstract the specific nature of the data client through the use of interfaces. If you are worried about having to change databases during the lifespan of an app, utilizing these interfaces instead of the actual objects keeps your code maintainable.
C#:


SqlConnection connection = new SqlConnection();
IDbCommand cmd = connection.CreateCommand();
IDataParameter param = cmd.CreateParameter();

Using this simple pattern, the only thing you would have to change besides special parameters (like text, image, etc) is the connection object and DataAdapters. YOu could abstract those away with a factory interface.

As a matter of fact, I have written a data provider independant database client with a SqlFactory built in. Find it at http://brandon.gobigfishgo.com under 'Open Source'

I think you should look at a very informative newsletter about these interfaces at
http://www.bytefx.com/newsletter.aspx
You have to 'register' or whatever to actually see it, but it will be a lot more informative than I can be here.|||Really depends on the load to decide whether it would be worth it. SqlClient namespace classes implement a TDSParser which means they deal directly with the stream coming back from SQL; whereas OLEDB stuff runs through a more generic filter.

In your position I would look at the effort to convert, versus the actual chance that the application would be under such a stressful mode that users would experience the slight difference in performance.

Monday, March 19, 2012

OleDB Connection to Excel

Hi,

My application connects to excel files.
I am using this code:



dc = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + fileName + ";" +
"Extended Properties=\"Excel 8.0;HDR=YES;\"");

It works fine on Excel 2000 on all computers. Also it works on some computers with Excel 2002/XP, but on some computers with Excel 2002/XP it doesn't work.

How can I solve it?

Thank's
AlexeiHi,
I used above code sample for my program. but i did not worked.can u help me. I want to do ,take excel information to one record set or data set.I can't understand how to do it.I send u my connection coding.please check it send me wht is the correct syntax or correct code and tell me wht is the componts want. this program using the .net
following has my codes:

MyConnection = New OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;data source=D:\Oven Sheet (Track)\Data For Symix_23082005-Tracks.xls;Extended Properties=\Excel 8.0")

|||Are you sure you have the right version of Jet on the machine? Check this by right clicking on the desktop and create a new text file, call it demo.udl. This is a datalink file. If you double click on the file it should show you a list of OLE DB Providers, check that Jet 4.0 is installed.

If it is installed then try changing \Excel 8.0 to plain Excel 8.0