Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
using connection string in sql i saved the data.All records are there in the data base.

i want to MS Access Database to store the record in MS Access DataBase.

Sql conncetion string as follows;

private string himtConnectionString = "Data Source=india;connect timeout = 120; Initial Catalog=HIMTTESTing;User ID=sgv;Password =s123 ";

how to write connection string for MS Access Data Base.


private string Accessconncetionstring = "Provider = microsoft.jet.OLEDB.4.0;Data Source=C:\HIMTTESTing.mdb";


the above Accessconncetionstring for MS Access is correct.please help me.


how can i do.

i don't know.please help me.i want the answer.
Posted

1 solution

The connection string for MS Access 2007 database can also be stored inside the web.config file to connect it to the ASP.Net web page using C#. In MS Access 2007 the Microsoft has introduced a new database file type that is .accdb extension. The internal features of the MS Access 2007 can be performed normally like in the previous versions. You can create the MS Access Database and save it into the App_Data directory of the ASP.Net web application. The App_Data directory is also a new feature of ASP.Net 2.0 framework that enables you to store the data items inside it as secure items that cannot be accessed using http request openly. The MS Access 2007 database can be connected using the OleDb data provider of ASP.Net framework that enables you to connect and perform the data operations using C# code easily.

XML
<connectionStrings>
    <!-- connection string declared for connecting the web application with MS Access 2007 -->
    <!-- connection string for MS Access 2007 accdb file -->
    <add name="AccessConnectionString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|db1.accdb;Persist Security Info=False;Jet OLEDB:Database Password=;" providerName="System.Data.OleDb" />
</connectionStrings>


C# Code for Connecting the Web Page to MS Access 2007 Database File

Namespace Required
C#
// import the following namespaces
   using System.Configuration;
   using System.Data;
   using System.Data.OleDb;


// create an OldDbConnection object and initialize it by passing connection string.
// ConfigurationManager class provides the ConnectionStrings collection type property
// to access the connection string stored in the web.config file.
OleDbConnection myDataConnection = new OleDbConnection(ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString);

// open the data connection.
myDataConnection.Open();

// display the connection's current state open/closed.
Response.Write(string.Format("<i><b>Connection state:</b> {0}</i><br />", myDataConnection.State));

// close the data connection.
myDataConnection.Close();

// again display the connection's current state open/closed.
Response.Write(string.Format("<i><b>Connection state:</b> {0}</i>", myDataConnection.State));

// dispose the connection object to release the resources.
myDataConnection.Dispose();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900