如何在MSAccess中使用conncetion字符串 [英] how to use conncetion string in MSAccess

查看:59
本文介绍了如何在MSAccess中使用conncetion字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在sql中使用连接字符串我保存了数据。所有记录都在数据库中。



i希望MS Access数据库在MS Access中存储记录数据库。



Sql conncetion字符串如下;



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



如何为MS Access数据库写连接字符串。





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





上面的MS Access Accessconncetionstring是正确的。请帮助我。





我该怎么办。



i不知道。请帮助我。我想要答案。

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.

推荐答案

MS Access 2007数据库的连接字符串也可以存储insid使用C#将web.config文件连接到ASP.Net网页。在MS Access 2007中,Microsoft引入了一种新的数据库文件类型,即.accdb扩展名。 MS Access 2007的内部功能可以像以前的版本一样正常执行。您可以创建MS Access数据库并将其保存到ASP.Net Web应用程序的App_Data目录中。 App_Data目录也是ASP.Net 2.0框架的一项新功能,使您可以将其中的数据项存储为无法使用http请求公开访问的安全项。可以使用ASP.Net框架的OleDb数据提供程序连接MS Access 2007数据库,使您可以轻松地使用C#代码连接和执行数据操作。



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.

<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>





用于将网页连接到MS Access 2007数据库文件的C#代码



名称空间必需



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

Namespace Required

// 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();


这篇关于如何在MSAccess中使用conncetion字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆