ali durgun
ali durgun

Reputation: 23

How to set the provider in the connection string for OleDbConnection?

I am trying to create a connection to my database via OleDbConnection, but I do not know how to specify the provider.

DataSet ds = new DataSet();
OleDbConnection baglanti = new OleDbConnection();
baglanti.ConnectionString = @"Provider=.NET Framework Data Provider for SQL Server;Data Source=project.mdb";
OleDbDataAdapter adapter = new OleDbDataAdapter(komut, baglanti);
adapter.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];

Upvotes: 0

Views: 1675

Answers (2)

Iske
Iske

Reputation: 1200

Create new Text Document and save it. Change the extension from .txt to .udl and then run it. On the provider tab select appropriate provider and click Next. After that, in the Data Source field, copy and paste the path to your database location followed by database name:

C:\..your path..\project.mdb

After that you can click Test Connection button and see if it connects. If test was successful, click OK.

At very the end, open .udl file with Notepad or simmilar and there you will have Connection string with provider and everything...

Hope this helps you.

Upvotes: 0

Kiril Rusalov
Kiril Rusalov

Reputation: 15

This is for Sql Database, but it may work with an access database.

Import the .mdb file to your project, and then open it in your server explorer, when selected it will show you your connectionstring

enter image description here

Upvotes: 1

Related Questions