Home > Database > Mysql Tutorial > ado.net 连接vs 数据库代码

ado.net 连接vs 数据库代码

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 17:47:32
Original
1081 people have browsed it

ado.net 连接vs 代码

可以利用这个连接向导配置连接到access数据库文件、odbc数据源、sql server数据库、sql server手机版数据库、sql server数据库文件、oracle数据库文件及其它数据库。
在这里我们选择microsoft sql server选项,连接到sql server数据库。如果我们在局域网中,我们可以点击“添加连接”界面中的刷新按钮来查看局域网中有哪些sql server数据库可以连接。连接到数据库可以用下面的方式:
(1)如果要连接的数据库服务器与开发者的机器在同一个局域网里,可以使用局域网ip地址或者局域网中的电脑主机名;
(2)如果要连接的数据库服务器与开发者的机器不在同一个局域网内,那么就要求数据库服务器必须有一个公网ip,我们可以使用公网ip来连接,如果数据库服务器还有互联网域名,那么用互联网域名也是可以的。
(3)如果要连接的数据库服务器与开发者所使用的机器是同一台机器,那么可以使用以下几种方式之一:”(local)”或者”.”或者”127.0.0.1”。

下面看一下代码


server=.sqlexpress;attachdbfilename=|datadirectory|mydbfile.mdf; database=dbname;trusted_connection=yes;
data source=.sqlexpress;integrated security=true; attachdbfilename=|datadirectory|mydb.mdf;user instance=true;


针对sql server数据库讲述connection、command、dataadapter和datareader对象的用法,它们在其它数据库中也有对应的类,除了有些sql语句语法不一样之外,用法是基本一样的。

connection对象
connection对象也称为数据库连接对象,connection对象的功能是负责对数据源的连接。所有connection对象的基类都是dbconnection类。
connection对象有两个重要属性:
connectionstring:表示用于打开 sql server 数据库的字符串;
state:表示 connection 的状态,有closed和open两种状态。
connection对象有两个重要方法:
open()方法:指示打开数据库;
close()方法:指示关闭数据库。
在实际开发中很多朋友经常询问数据库连接字符串该怎么写,其实有一个很简单的技巧,我们可以在visual studio 2005工具箱中找到数据分组

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template