开发者

How can I write connectiong for Access database?

I am working with MS Access databse for the first time. I deployed my appilcaton on my server. I have access database on my system (D:\Database).

<appSettings>
    <add key="dbcon" value="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=  ?  "/>

</app开发者_运维知识库Settings>
<connectionStrings>

When I am trying to connect it is giving error.

How can I modify my connection string?

Regards, NS


I'm assuming that the database have an extension of .mdb, otherwise change it to whatever is needed:

<add key="dbcon" value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Database.mdb"/>

So all you needed to do was to add the name of the db file to the connection string.

You can find more samples here.


System.Data.OleDb.OleDbConnection conn = new 
System.Data.OleDb.OleDbConnection();
// TODO: Modify the connection string and include any
// additional required properties for your database.
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
@"Data source= C:\Documents and Settings\username\" +
@"My Documents\AccessFile.mdb";

now modify your connection:

ConfigurationSettings.AppSettings["dbcon"] =  conn.ConnectionString;//the new connection;

Read more ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜