用户操作
[即时聊天] [发私信] [加为好友]
李璧扬ID:libiyang
17970次访问,排名6900,好友0人,关注者0人。
libiyang的文章
原创 27 篇
翻译 0 篇
转载 9 篇
评论 6 篇
libiyang的公告

时钟日历:

今明天气:


最近评论
domemy:2008 Installshield软件用户技术交流会
作为软件技术的精英、应用者和关注者,如果您没有用过InstallShield,也一定听说过它!
作为Acresso公司的主打产品,InstallShield拥有20年的打包应用程序经验,在不断完善中,大步前行!
由于InstallShield功能强大、灵活性好、完全可扩展以及具有强有力的网络支持,在各种安装……
bluehouse1985:InstallShield & InstallAnywhere 涨价前最后一次特卖!
Acresso公司主打产品installshield和installanywhere从11月1日起全面涨价!InstallShield & InstallAnywhere 涨价前最后一次特卖!仅10天!先到先得!
为庆祝最新版InstallShield 2009 &……
bluehouse1985:InstallShield 2009 升级优惠中!
为庆祝最新版InstallShield 2009上市,答谢广大新老用户的支持与厚爱,从即日起,上海世全软件(XLsoft)举办InstallShield 2009优惠活动!数量有限,售完为止!
销售热线:021-62128912/010-64616123
销售邮箱:sales@XLsoft.com.cn
lufree:请问为何我把protection="All"就不行?把protection="None"就可以?

加密?
yinweicai:需要把用户名改成dbo
文章分类
收藏
相册
友情链接
21世纪asp.net技术网
SQL Server杂志
周奕(共享软件)
孟子E章
小虫的窝
李洪波的Blog
水晶报表方面的
存档
软件项目交易
订阅我的博客
XML聚合  FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
订阅到BlogLines
订阅到Yahoo
订阅到GouGou
订阅到飞鸽
订阅到Rojo
订阅到newsgator
订阅到netvibes

转载 .net的数据库连接字符串收藏

新一篇: 同时查询两个数据库的问题 | 

在MSDN中,.net的数据库连接字符串都有详细的说明,我这里以代码范例的方式罗列一些,具体的每一项代表的意义可以参看MSDN.

ADO.net 中数据库连接方式(微软提供)

微软提供了以下四种数据库连接方式:
System.Data.OleDb.OleDbConnection
System.Data.SqlClient.SqlConnection
System.Data.Odbc.OdbcConnection
System.Data.OracleClient.OracleConnection
下面我们以范例的方式,来依次说明:

System.Data.SqlClient.SqlConnection
常用的一些连接字符串(C#代码):

SqlConnection conn = new SqlConnection( "Server=(local);Integrated Security=SSPI;database=Pubs");

SqlConnection conn = new SqlConnection("server=(local)\NetSDK;database=pubs;Integrated Security=SSPI");

SqlConnection conn = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;");

SqlConnection conn = new SqlConnection(" data source=(local);initial catalog=xr;integrated security=SSPI;
persist security info=False;workstation id=XURUI;packet size=4096; ");

SqlConnection myConn  = new System.Data.SqlClient.SqlConnection("Persist Security Info=False;Integrated
Security=SSPI;database=northwind;server=mySQLServer");

SqlConnection conn = new SqlConnection( " uid=sa;pwd=passwords;initial catalog=pubs;data source=127.0.0.1;Connect Timeout=900");

更多字符串连接说明请看MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataSqlClientSqlConnectionClassConnectionStringTopic.asp

System.Data.OleDb.OleDbConnection
常用的一些连接字符串(C#代码):

OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\MyWeb5\GrocerToGo.mdb");

OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Password=;
User ID=Admin;Data Source=grocertogo.mdb;");

OleDbConnection conn = new OleDbConnection("Provider=MSDAORA; Data Source=ORACLE8i7;Persist Security Info=False;Integrated Security=yes");

OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\bin\LocalAccess40.mdb");

OleDbConnection conn = new OleDbConnection("Provider=SQLOLEDB;Data Source=MySQLServer;Integrated Security=SSPI");

更多字符串连接说明请看MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataOleDbOleDbConnectionClassConnectionStringTopic.asp?frame=true
System.Data.OracleClient.OracleConnection
常用的一些连接字符串(C#代码):
OracleConnection myConn = new System.Data.OracleClient.OracleConnection(
"Data Source=Oracle8i;Integrated Security=yes");

更多字符串连接说明请看MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataOracleClientOracleConnectionClassConnectionStringTopic.asp?frame=true
System.Data.Odbc.OdbcConnection
常用的一些连接字符串(C#代码):
OdbcConnection conn = new OdbcConnection(
"Driver={SQL Server};Server=MyServer;Trusted_Connection=yes;Database=Northwind;");

OdbcConnection conn = new OdbcConnection(
"Driver={Microsoft ODBC for Oracle};Server=ORACLE8i7;
Persist Security Info=False;Trusted_Connection=yes");

OdbcConnection conn = new OdbcConnection(
"Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\bin\nwind.mdb");

OdbcConnection conn = new OdbcConnection(
"Driver={Microsoft Excel Driver (*.xls)};DBQ=c:\bin\book1.xls");


OdbcConnection conn = new OdbcConnection(
"Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=c:\bin");

OdbcConnection conn = new OdbcConnection("DSN=dsnname");

更多字符串连接说明请看MSDN:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataOdbcOdbcConnectionClassConnectionStringTopic.asp?frame=true


其他厂商提供的数据库连接:

DB2Connection myConn = new IBM.Data.DB2.DB2Connection(
"DATABASE = SAMPLE;UID=<username>; PWD=<password>;");

DB2Connection myConn = new IBM.Data.DB2.DB2Connection("DATABASE = SAMPLE");


BdpConnection myConn = new Borland.Data.Provider.BdpConnection("assembly=Borl
and.Data.Mssql,Version=1.1.0.0,Culture=neutral,PublicKeyToken=91d62ebb5b0d1b1b;ve
ndorclient=sqloledb.dll;osauthentication=False;database=<database>;usernam
e=<user>;hostname=<host>;password=<password>;provider=MSSQL");

BdpConnection myConn = new Borland.Data.Provider.BdpConnection("assembly=Borl
and.Data.Db2,Version=1.1.0.0,Culture=neutral,PublicKeyToken=91d62ebb5b0d1b1b;ve
ndorclient=db2cli.dll;database=<database>;username=<user>;
password=<password>;provider=DB2");


Connection Pooling


在SQL Server、OLE DB和.NET框架结构中的Data Provider中,都提供了隐式的连接池连接支持。你可以在ConnectionString中指定不同的参数值控制连接池的行为。比如下面的例子使OLE DB的连接池无效并自动地进行事务处理:
Provider=SQLOLEDB;OLE DB Services=-4;Data Source=localhost;Integrated Security=SSPI;
在SQL Server.NET Data Provider中提供了以下参数设置控制连接池的行为:Connection Lifttime、Connection Reset、Enlist、Max Pool Size、Min Pool Size和Pooling

发表于 2004年09月06日 12:25 PM

评论

# 回复:ADO.net 中数据库连接方式(微软提供) 2004-09-06 7:57 PM cry_out
利用odbc连接后,要用那个command呢? sqlconnection 是sqlcommand, oledbconnection 是oledbconnection那么,利用odbc后,要用那个command呢?

# 回复:ADO.net 中数据库连接方式(微软提供) 2004-09-07 10:45 AM abao
当然有OdbcCommand

http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDataOdbcOdbcCommandClassTopic.asp?frame=true

For a list of all members of this type, see OdbcCommand Members.

System.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Data.Odbc.OdbcCommand

[Visual Basic]
NotInheritable Public Class OdbcCommand
Inherits Component
Implements ICloneable, IDbCommand
[C#]
public sealed class OdbcCommand : Component, ICloneable, IDbCommand
[C++]
public __gc __sealed class OdbcCommand : public Component,
ICloneable, IDbCommand
[JScript]
public class OdbcCommand extends Component implements ICloneable,
IDbCommand


# 回复:ADO.net 中数据库连接方式(微软提供) 2004-09-07 10:46 AM abao
[C#]
public void ReadMyData(string myConnString)
{
string mySelectQuery = "SELECT OrderID, CustomerID FROM Orders";
OdbcConnection myConnection = new OdbcConnection(myConnString);
OdbcCommand myCommand = new OdbcCommand(mySelectQuery,myConnection);
myConnection.Open();
OdbcDataReader myReader = myCommand.ExecuteReader();
try
{
while (myReader.Read())
{
Console.WriteLine(myReader.GetInt32(0) + ", " + myReader.GetString(1));
}
}
finally
{
// always call Close when done with connection.
myReader.Close();
// always call Close when done with connection.
myConnection.Close();
}
}

发表于 @ 2004年09月09日 10:46:00|评论(loading...)|编辑

新一篇: 同时查询两个数据库的问题 | 

评论:没有评论。

发表评论  


当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
Csdn Blog version 3.1a
Copyright © libiyang