电信主站 网通分站
购买流程 付款方式 常见问题 在线提问 续租服务 购物车
用户名: 密 码: 忘记密码?
首 页
域名注册
虚拟主机
双线主机
服务器租用
VPS主机
企业邮局
代理专区
客服中心
虚拟主机行业资讯 虚拟主机评测对比 互联网最新动态 技术学院 站长资讯 在线教程 网站运营
搜索优化 服务器 网络编程 图形图象 站长之家 网页制作 操作系统
冲浪宝典 软件教学 视频通信 办公软件 邮件系统 网络安全 认证考试
您当前位置:西部数码->资讯中心-> 在线教程-> 数据库
C#数据库连接字符大全-.NET教程,C#语言
作者:网友供稿 点击:15
  西部数码-全国虚拟主机10强!20余项虚拟主机管理功能,全国领先!第6代双线路虚拟主机,南北访问畅通无阻!虚拟主机可在线rar解压,自动数据恢复设置虚拟目录等.虚拟主机免费赠送访问统计,企业邮局.Cn域名注册10元/年,自助建站480元起,免费试用7天,满意再付款!P4主机租用799元/月.月付免压金!
文章页数:[1] 
sql server
odbc


standard security:

"driver={sql server};server=aron1;database=pubs;uid=sa;pwd=asdasd;"



trusted connection:

"driver={sql server};server=aron1;database=pubs;trusted_connection=yes;"



prompt for username and password:

oconn.properties("prompt") = adpromptalways
oconn.open "driver={sql server};server=aron1;database=pubs;"



ole db, oledbconnection (.net)


standard security:

"provider=sqloledb;data source=aron1;initial catalog=pubs;user id=sa;password=asdasd;"



trusted connection:

"provider=sqloledb;data source=aron1;initial catalog=pubs;integrated security=sspi;"
(use servername\instancename as data source to use an specifik sqlserver instance, only sqlserver2000)
prompt for username and password:

oconn.provider = "sqloledb"
oconn.properties("prompt") = adpromptalways
oconn.open "data source=aron1;initial catalog=pubs;"



connect via an ip address:

"provider=sqloledb;data source=190.190.200.100,1433;network library=dbmssocn;initial catalog=pubs;user id=sa;password=asdasd;"
(dbmssocn=tcp/ip instead of named pipes, at the end of the data source is the port to use (1433 is the default))
sqlconnection (.net)


standard security:

"data source=aron1;initial catalog=pubs;user id=sa;password=asdasd;"
- or -
"server=aron1;database=pubs;user id=sa;password=asdasd;trusted_connection=false"
(booth connection strings produces the same result)




trusted connection:

"data source=aron1;initial catalog=pubs;integrated security=sspi;"
- or -
"server=aron1;database=pubs;trusted_connection=true;"
(booth connection strings produces the same result)

(use servername\instancename as data source to use an specifik sqlserver instance, only sqlserver2000)
connect via an ip address:

"data source=190.190.200.100,1433;network library=dbmssocn;initial catalog=pubs;user id=sa;password=asdasd;"
(dbmssocn=tcp/ip instead of named pipes, at the end of the data source is the port to use (1433 is the default))
declare the sqlconnection:

c#:
using system.data.sqlclient;
sqlconnection osqlconn = new sqlconnection();
osqlconn.connectionstring="my connectionstring";
osqlconn.open();



vb.net:
imports system.data.sqlclient
dim osqlconn as sqlconnection = new sqlconnection()
osqlconn.connectionstring="my connectionstring"
osqlconn.open()



data shape


ms data shape
"provider=msdatashape;data provider=sqloledb;data source=aron1;initial catalog=pubs;user id=sa;password=asdasd;"
want to learn data shaping? check out 4guyffromrollas great article about data shaping >>
read more


how to define which network protocol to use


example:
"provider=sqloledb;data source=190.190.200.100,1433;network library=dbmssocn;initial catalog=pubs;user id=sa;password=asdasd;"

name network library
dbnmpntw win32 named pipes
dbmssocn win32 winsock tcp/ip
dbmsspxn win32 spx/ipx
dbmsvinn win32 banyan vines
dbmsrpcn win32 multi-protocol (windows rpc)


important note!
when connecting through the sqloledb provider use the syntax network library=dbmssocn
and when connecting through msdasql provider use the syntax network=dbmssocn


all sqlconnection connectionstring properties


this table shows all connectionstring properties for the ado.net sqlconnection object. most of the properties are also used in ado. all properties and descriptions is from msdn.

name default description
application name the name of the application, or .net sqlclient data provider if no application name is provided.
attachdbfilename
-or-
extended properties
-or-
initial file name the name of the primary file, including the full path name, of an attachable database. the database name must be specified with the keyword database.
connect timeout
-or-
connection timeout 15 the length of time (in seconds) to wait for a connection to the server before terminating the attempt and generating an error.
connection lifetime 0 when a connection is returned to the pool, its creation time is compared with the current time, and the connection is destroyed if that time span (in seconds) exceeds the value specified by connection lifetime. useful in clustered configurations to force load balancing between a running server and a server just brought on-line.
connection reset true determines whether the database connection is reset when being removed from the pool. setting to false avoids making an additional server round-trip when obtaining a connection, but the programmer must be aware that the connection state is not being reset.
current language the sql server language record name.
data source
-or-
server
-or-
address
-or-
addr
-or-
network address the name or network address of the instance of sql server to which to connect.
enlist true when true, the pooler automatically enlists the connection in the creation threads current transaction context.
initial catalog
-or-
database the name of the database.
integrated security
-or-
trusted_connection false whether the connection is to be a secure connection or not. recognized values are true, false, and sspi, which is equivalent to true.
max pool size 100 the maximum number of connections allowed in the pool.
min pool size 0 the minimum number of connections allowed in the pool.
network library
-or-
net dbmssocn the network library used to establish a connection to an instance of sql server. supported values include dbnmpntw (named pipes), dbmsrpcn (multiprotocol), dbmsadsn (apple talk), dbmsgnet (via), dbmsipcn (shared memory) and dbmsspxn (ipx/spx), and dbmssocn (tcp/ip).
the corresponding network dll must be installed on the system to which you connect. if you do not specify a network and you use a local server (for example, "." or "(local)"), shared memory is used.
packet size 8192 size in bytes of the network packets used to communicate with an instance of sql server.
password
-or-
pwd the password for the sql server account logging on.
persist security info false when set to false, security-sensitive information, such as the password, is not returned as part of the connection if the connection is open or has ever been in an open state. resetting the connection string resets all connection string values including the password.
pooling true when true, the sqlconnection object is drawn from the appropriate pool, or if necessary, is created and added to the appropriate pool.
user id the sql server login account.
workstation id the local computer name the name of the workstation connecting to sql server.


note
use ; to separate each property.
if a name occurs more than once, the value from the last one in the connectionstring will be used.
if you are building your connectionstring in your app using values from user input fields, make sure the user cant change the connectionstring by inserting an additional property with another value within the user value.
access
odbc


standard security:

"driver={microsoft access driver (*.mdb)};dbq=c:\mydatabase.mdb;uid=admin;pwd=;"



workgroup:

"driver={microsoft access driver (*.mdb)};dbq=c:\mydatabase.mdb;systemdb=c:\mydatabase.mdw;"



exclusive:

"driver={microsoft access driver (*.mdb)};dbq=c:\mydatabase.mdb;exclusive=1;uid=admin;pwd="



ole db, oledbconnection (.net)


standard security:

"provider=microsoft.jet.oledb.4.0;data source=\somepath\mydb.mdb;user id=admin;password=;"



workgroup (system database):

"provider=microsoft.jet.oledb.4.0;data source=\somepath\mydb.mdb;jet oledb:system database=system.mdw;"



with password:

"provider=microsoft.jet.oledb.4.0;data source=\somepath\mydb.mdb;jet oledb:database password=mydbpassword;"



oracle
odbc


new version:

"driver={microsoft odbc for oracle};server=oracleserver.world;uid=username;pwd=asdasd;"



old version:

"driver={microsoft odbc driver for oracle};connectstring=oracleserver.world;uid=myusername;pwd=mypassword;"



ole db, oledbconnection (.net)


standard security:

"provider=msdaora;data source=myoracledb;user id=username;password=asdasd;"
this ones from microsoft, the following are from oracle
standard security:

"provider=oraoledb.oracle;data source=myoracledb;user id=username;password=asdasd;"



trusted connection:

"provider=oraoledb.oracle;data source=myoracledb;osauthent=1;"



oracleconnection (.net)


standard:

"data source=myoracledb;integrated security=yes;"
this one works only with oracle 8i release 3 or later
specifying username and password:

"data source=myoracledb;user id=username;password=passwd;integrated security=no;"
this one works only with oracle 8i release 3 or later
declare the oracleconnection:

c#:
using system.data.oracleclient;
oracleconnection ooracleconn = new oracleconnection();
ooracleconn.connectionstring = "my connectionstring";
ooracleconn.open();



vb.net:
imports system.data.oracleclient
dim ooracleconn as oracleconnection = new oracleconnection()
ooracleconn.connectionstring = "my connectionstring"
ooracleconn.open()



missing the system.data.oracleclient namespace? download .net managed provider for oracle »
great article! "features of oracle data provider for .net" by rama mohan g. at c# corner
core labs oradirect (.net)


standard:
"user id=scott; password=tiger; host=ora; pooling=true; min pool size=0;max pool size=100; connection lifetime=0"
read more at core lab and the product page.
data shape


ms data shape:
"provider=msdatashape.1;persist security info=false;data provider=msdaora;data source=orac;user id=username;password=mypw"
want to learn data shaping? check out 4guyffromrollas great article about data shaping >>
mysql
odbc


odbc 2.50 local database:

"driver={mysql};server=localhost;option=16834;database=mydatabase;"



odbc 2.50 remote database:

"driver={mysql};server=data.domain.com;port=3306;option=131072;stmt=;database=my-database;uid=username;pwd=password;"



odbc 3.51 local database:

"driver={mysql odbc 3.51 driver};server=localhost;database=mydatabase;user=myusername;password=mypassword;option=3;"



odbc 3.51 remote database:

"driver={mysql odbc 3.51 driver};server=data.domain.com;port=3306;database=mydatabase;user=myusername;password=mypassword;option=3;"



ole db, oledbconnection (.net)


standard:

"provider=mysqlprov;data source=mydb;user id=username;password=asdasd;"
mysqlconnection (.net)


einfodesigns.dbprovider:

"data source=server;database=mydb;user id=username;password=pwd;command logging=false"
this one is used with einfodesigns dbprovider, an add-on to .net
declare the mysqlconnection:

c#:
using einfodesigns.dbprovider.mysqlclient;
mysqlconnection omysqlconn = new mysqlconnection();
omysqlconn.connectionstring = "my connectionstring";
omysqlconn.open();



vb.net:
imports einfodesigns.dbprovider.mysqlclient
dim omysqlconn as mysqlconnection = new mysqlconnection()
omysqlconn.connectionstring = "my connectionstring"
omysqlconn.open()



sevenobjects mysqlclient (.net)


standard:

"host=server; username=myusername; password=mypassword;database=mydb;"
this is a freeware ado.net data provider from sevenobjects
core labs mysqldirect (.net)


standard:

"user id=root; password=pwd; host=localhost; port=3306; database=test;direct=true; protocol=tcp; compress=false; pooling=true; min pool size=0;max pool size=100; connection lifetime=0"
read more at core lab and the product page.
interbase
odbc, easysoft


local computer:

"driver={easysoft ib6 odbc};server=localhost;database=localhost:c:\mydatabase.gdb;uid=username;pwd=password"



remote computer:

"driver={easysoft ib6 odbc};server=computername;database=computername:c:\mydatabase.gdb;uid=username;pwd=password"
read more about this driver: easysoft odbc-interbase driver >>

odbc, intersolv


local computer:

"driver={intersolv interbase odbc driver (*.gdb)};server=localhost;database=localhost:c:\mydatabase.gdb;uid=username;pwd=password"



remote computer:

"driver={intersolv interbase odbc driver (*.gdb)};server=computername;database=computername:c:\mydatabase.gdb;uid=username;pwd=password"
this driver are provided by datadirect technologies >> (formerly intersolv)



ole db, sibprovider


standard:

"provider=sibprovider;location=localhost:;data source=c:\databases\gdbs\mygdb.gdb;user id=sysdba;password=masterkey"



specifying character set:

"provider=sibprovider;location=localhost:;data source=c:\databases\gdbs\mygdb.gdb;user id=sysdba;password=masterkey;character set=iso8859_1"



specifying role:

"provider=sibprovider;location=localhost:;data source=c:\databases\gdbs\mygdb.gdb;user id=sysdba;password=masterkey;role=digitadores"
read more about sibprovider >>




read more about connecting to interbase in this borland developer network article http://community.borland.com/article/0,1410,27152,00.html


ibm db2
ole db, oledbconnection (.net) from ms


tcp/ip:

"provider=db2oledb;network transport library=tcpip;network address=xxx.xxx.xxx.xxx;initial catalog=myctlg;package collection=mypkgcol;default schema=schema;user id=myuser;password=mypw"



appc:

"provider=db2oledb;appc local lu alias=myalias;appc remote lu alias=myremote;initial catalog=myctlg;package collection=mypkgcol;default schema=schema;user id=myuser;password=mypw"



ibms ole db provider (shipped with ibm db2 udb v7 or above)


tcp/ip:

provider=ibmdadb2;database=sample;hostname=db2host;protocol=tcpip;port=50000;uid=myusername;pwd=mypwd;



odbc


standard:

"driver={ibm db2 odbc driver};database=mydbname;hostname=myservername;port=myportnum;protocol=tcpip; uid=myusername; pwd=mypwd"



sybase
odbc


standard sybase system 12 (or 12.5) enterprise open client:

"driver={sybase ase odbc driver};srvr=aron1;uid=username;pwd=password"



standard sybase system 11:

"driver={sybase system 11};srvr=aron1;uid=username;pwd=password;"
do you know a userguide for sybase system 11, 12, 12.5? e-mail the url to connectionstrings.com now!! >>
intersolv 3.10:

"driver={intersolv 3.10 32-bit sybase};srvr=aron1;uid=username;pwd=password;"



sybase sql anywhere (former watcom sql odbc driver):

"odbc; driver=sybase sql anywhere 5.0; defaultdir=c:\dbfolder\;dbf=c:\mydatabase.db;uid=username;pwd=password;dsn="""""
note! the two double quota following the dsn parameter at the end are escaped quotas (vb syntax), you may have to change this to your language specific escape syntax. the empty dsn parameter is indeed critical as not including it will result in error 7778.


read more in the sybase sql anywhere user guide >>
ole db


adaptive server anywhere (asa):

"provider=asaprov;data source=myasa"
read more in the asa user guide >>
adaptive server enterprise (ase) with data source .ids file:

"provider=sybase ase ole db provider; data source=myase"
note that you must create a data source .ids file using the sybase data administrator. these .ids files resemble odbc dsns.
adaptive server enterprise (ase):

"provider=sybase.aseoledbprovider;srvr=myaseserver,5000;catalog=mydbname;user id=username;password=password"
- some reports on problem using the above one, try the following as an alternative -

"provider=sybase.aseoledbprovider;server name=myaseserver,5000;initial catalog=mydbname;user id=username;password=password"
this one works only from open client 12.5 where the server port number feature works,燼llowing fully qualified connection strings to be used without defining燼ny .ids data source files.
aseconnection (.net)


standard:

"data source=myaseserver;port=5000;database=mydbname;uid=username;pwd=password;"



declare the aseconnection:

c#:
using sybase.data.aseclient;
aseconnection ocon = new aseconnection();
ocon.connectionstring="my connection string";
ocon.open();



vb.net:
imports system.data.aseclient
dim ocon as aseconnection = new aseconnection()
ocon.connectionstring="my connection string"
ocon.open()



informix
odbc


informix 3.30:

"dsn=;driver={informix 3.30 32 bit};host=hostname;server=myserver;service=service-name;protocol=olsoctcp;database=mydb;uid=username;pwd=mypwd



informix-cli 2.5:

"driver={informix-cli 2.5 (32 bit)};server=myserver;database=mydb;uid=username;pwd=mypwd"



ole db


ibm informix ole db provider:

"provider=ifxoledbc.2;password=mypw;user id=myuser;data source=dbname@servername;persist security info=true"



ingres
odbc


dsn-less

"provider=msdasql.1;driver=ingres;srvr=xxxxx;db=xxxxx;persist security info=false;uid=xxxx;pwd=xxxxx;selectloops=n;extended properties="""server=xxxxx;database=xxxxx;servertype=ingres""



mimer sql
odbc


standard security:

"driver={mimer};database=mydb;uid=myuser;pwd=mypw;"



prompt for username and password:

"driver={mimer};database=mydb;"



lightbase
standard


standard:

"user=userlogin;password=password;udb=userbase;server=servername"



postgresql
core labs postgresqldirect (.net)


standard:

"user id=root; password=pwd; host=localhost; port=5432; database=testdb;pooling=true; min pool size=0; max pool size=100; connection lifetime=0"
read more at core lab and the product page.



dsn
odbc


dsn:

"dsn=mydsn;uid=username;pwd=;"



file dsn:

"filedsn=c:\mydata.dsn;uid=username;pwd=;"



firebird
odbc - ibphoenix open source


standard:

"driver=firebird/interbase(r) driver;uid=sysdba;pwd=masterkey;dbname=d:\firebird\examples\test.fdb"
ibphoenix odbc; more info, download etc >>
.net - firebird .net data provider


standard:

"user=sysdba;password=masterkey;database=sampledatabase.fdb;datasource=localhost;port=3050;dialect=3;charset=none;role=;connection lifetime=15;pooling=true;minpoolsize=0;maxpoolsize=50;packet size=8192;servertype=0"
firebird ado.net project >>
firebird ado.net downloads >>
excel
odbc


standard:

"driver={microsoft excel driver (*.xls)};driverid=790;dbq=c:\myexcel.xls;defaultdir=c:\mypath;"
tip! sql syntax: "select * from [sheet1$]" - i.e. worksheet name followed by a "$" and wrapped in "[" "]" brackets.
ole db


standard:

"provider=microsoft.jet.oledb.4.0;data source=c:\myexcel.xls;extended properties=""excel 8.0;hdr=yes;imex=1"""
"hdr=yes;" indicates that the first row contains columnnames, not data
"imex=1;" tells the driver to always read "intermixed" data columns as text
tip! sql syntax: "select * from [sheet1$]" - i.e. worksheet name followed by a "$" and wrapped in "[" "]" brackets.
text
odbc


standard:

"driver={microsoft text driver (*.txt; *.csv)};dbq=c:\txtfilesfolder\;extensions=asc,csv,tab,txt;"



ole db


standard:

"provider=microsoft.jet.oledb.4.0;data source=c:\txtfilesfolder\;extended properties=""text;hdr=yes;fmt=delimited"""
"hdr=yes;" indicates that the first row contains columnnames, not data
dbf / foxpro
odbc


standard:

"driver={microsoft dbase driver (*.dbf)};driverid=277;dbq=c:\mydbpath;"



ole db, oledbconnection (.net)


standard:

"provider=microsoft.jet.oledb.4.0;data source=c:\folder;extended properties=dbase iv;user id=admin;password="



as/400
ole db


ibm client access ole db provider:

"provider=ibmda400; data source=my_system_name;uid=myusername;pwd=mypwd"
where my_system_name is the name given to the system connection in operationsnavigator
odbc


ibm client access odbc driver:

"driver={client access odbc driver (32-bit)};system=my_system_name;uid=myusername;pwd=mypwd"
exchange
ole db


exchange ole db provider:

"exoledb.datasource"
specify store in the connection open command like this: conn.open "http://servername/mypublicstore"

check out this article at msdn >> and this one at addison-wesley >>
visual foxpro
ole db, oledbconnection (.net)


database container (.dbc):

"provider=vfpoledb.1;data source=c:\mydbfolder\mydbcontainer.dbc;collating sequence=machine"



free table directory:

"provider=vfpoledb.1;data source=c:\mydatadirectory\;collating sequence=general"



force the provider to use an odbc dsn:

""provider=vfpoledb.1;dsn=mydsn""
read more (microsoft msdn) >>
odbc


database container (.dbc):

"driver={microsoft visual foxpro driver};sourcetype=dbc;sourcedb=c:\myvfpdb.dbc;exclusive=no;null=no;collate=machine;backgroundfetch=no;deleted=no"



free table directory:

"driver={microsoft visual foxpro driver};sourcetype=dbf;sourcedb=c:\myvfpdbfolder;exclusive=no;collate=machine;null=no;deleted=no;backgroundfetch=no"
"collate=machine" is the default setting, for other settings check the list of supported collating sequences >>

microsoft visual foxpro site: http://msdn.microsoft.com/vfoxpro


pervasive
odbc


standard:

"driver={pervasive odbc client interface};servername=srvname;dbq=@dbname"
pervasive odbc info >>
ole db


standard:

"provider=pervasiveoledb;data source=c:\path"
pervasive ole db info >>
udl
udl


udl:

"file name=c:\mydatalink.udl;"

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!
相关主题
文章页数:[1] 
Google
热门文章
·数据库开发个人总结(ADO.NET小结)-.NET教程,数据库应用
·怎么由DataSet将数据导入Excel?-.NET教程,数据库应用
·动态创建SQL Server数据库、表、存储过程-ASP教程,数据库相关
·Win32环境下动态链接库(DLL)编程原理-.NET教程,数据库应用
·封装的ADO.NET对数据库操作经典类-.NET教程,数据库应用
·在DataGridView中获得DataGridViewCheckBoxColumn的状态-ASP教程,数据库相关
·DataGrid使用心得(附大量代码)-ASP教程,数据库相关
·用代码创建DataGrid的多链接及checkbox事件响应-.NET教程,数据库应用
·ADO.NET 的最佳实践技巧-.NET教程,数据库应用
·转载: 用纯ASP代码实现图片上传并存入数据库中

最新文章
·根据数据表中数据,生成Powerpoint幻灯片-ASP教程,数据库相关
·DataGrid中的按钮反选事件与NamingContainer(命名容器)-downmoon-ASP教程,数据库相关
·使用用VB处理MYSQL数据库中二进制数据问题-.NET教程,VB.Net语言
·关于DataGridView中如何接收处于编辑状态下的当前信息-ASP教程,数据库相关
·在DataGridView中获得DataGridViewCheckBoxColumn的状态-ASP教程,数据库相关
·.net下访问Access数据库需要注意的问题-.NET教程,Asp.Net开发
·ActiveMQ4.1+Spring2.0的POJO JMS方案(上)-.NET教程,数据库应用
·ASP.NET 2.0中直接将Access数据库导入到Excel文件中-.NET教程,Asp.Net开发
·NET(C#)连接各类数据库-集锦-.NET教程,C#语言
·ASP.NET2.0连接SQL Server数据库详解-.NET教程,Asp.Net开发


 
 


版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!

特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。
  打印  刷新  关闭
返回首页 |关于我们 | 联系我们 | 付款方式 | 创业联盟 | 虚拟主机 | 资讯中心 | 友情链接 | 网站地图

版权所有 西部数码(www.west263.com)
CopyRight (c) 2002~2006 west263.com all right reserved.
公司地址:四川成都市万和路90号天象大厦4楼 邮编:610031
电话总机:028-86262244 86263048 86263408 86263960 86264018 86267838
售前咨询:总机转201 202 203 204 206 208
售后服务:总机转211 212 213 214
财务咨询:总机转224 223 传真:028-86264041 财务QQ:点击发送消息给对方635483282
售前咨询QQ:点击发送消息给对方2182518 点击发送消息给对方241975952 点击发送消息给对方275026793 点击发送消息给对方408235859
售后服务QQ:点击发送消息给对方17708515 点击发送消息给对方307742704 点击发送消息给对方287976517 点击发送消息给对方363783715
《中华人民共和国增值电信业务经营许可证》编号:川B2-20030065号