首 页 网络编程
网页制作 图形图象 操作系统 冲浪宝典
软件教学 认证考试

网络安全 网络办公 行业资讯 评测对比
您当前位置:站长天空 -> 软件教学
C#数据库连接字符大全-.NET教程,C#语言
作者:网友供稿 点击:1906
推荐
西部数码-全国虚拟主机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.z6688.com/
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

文章页数:[1] 


放大字体显示 缩小字体显示 打印文章 推荐给朋友
热门文章
·C#数据库连接字符大全-.NET教程,C#语言
·Ftp客户端编程-.NET教程,面向对象编程
·ASP.NET POST方式提交数据-.NET教程,Asp.Net开发
·单独控制IE WebControl里面的Treeview的几个动作的Postback-.NET教程,数据库应用
·根据IP找地址的java实现-JSP教程,Java技巧及代码
·ASP.NET 2.0 多文件上传小经验-.NET教程,Asp.Net开发
·ASP.NET 2.0中隐藏listbox的某一项-.NET教程,Asp.Net开发
·使用Windows Script 关闭和打开指定程序-.NET教程,数据库应用
·asp.net 2.0下嵌套masterpage页的可视化编辑-.NET教程,Asp.Net开发
·Jsp学习笔记(三)-----Jsp语法!-JSP教程,Jsp/Servlet
最新文章
·让windows vista系统只能识别自己指定的u盘_windows vista
·优化建议与技巧(来自adsense优化团队)_网赚技巧
·艾瑞曹军波:广告联盟发展的下一个突破点_网赚技巧
·狗狗网ceo李晶:80后创业 心态最重要_站长访谈
·从九句话看网站的综合发展_站长心得
·改进网页可读性的7个方法_站长心得
·常见问题_google adsense 广告点击统计_google推广
·10条优秀的网站设计经验1_站长心得
·怎样做个小网站_站长心得
·实施会员制计划中7项致命的失误_网站推广
相关主题
  • c#数据库操作的3种典型用法_c#应用
  • C#数据库事务原理及实践(上)-.NET教程,C#语言
  • C#数据库編程2-.NET教程,数据库应用
  • 西部数码虚拟主机

    友情链接
    CNNIC 西部数码
    万网 自助建站
    虚拟主机 asp空间
    域名注册 域名
    域名申请 主页空间
    论坛空间 网站空间
    国际域名 虚拟空间
    空间租用 DDOS防火墙
    成都主机托管 四川主机托管
    主机租用 服务器租用
    网站目录 自助建站
    虚拟主机 网址大全
    软件下载
    自助链接
    虚拟主机资讯 特价虚拟主机
    版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
    关于我们:站长天空:专业提供最新的站长资讯、在线教程、虚拟主机权威评测、虚拟主机性能对比、网站制作教程,开发教程,站长工具。包括网页制作教程、冲浪宝典、编程参考、操作系统、软件教学、行业动态等。
    特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。
    发表评论 打印  刷新     关闭