c#连接数据库代码集合Word格式.docx

上传人:b****4 文档编号:7890855 上传时间:2023-05-09 格式:DOCX 页数:21 大小:20.90KB
下载 相关 举报
c#连接数据库代码集合Word格式.docx_第1页
第1页 / 共21页
c#连接数据库代码集合Word格式.docx_第2页
第2页 / 共21页
c#连接数据库代码集合Word格式.docx_第3页
第3页 / 共21页
c#连接数据库代码集合Word格式.docx_第4页
第4页 / 共21页
c#连接数据库代码集合Word格式.docx_第5页
第5页 / 共21页
c#连接数据库代码集合Word格式.docx_第6页
第6页 / 共21页
c#连接数据库代码集合Word格式.docx_第7页
第7页 / 共21页
c#连接数据库代码集合Word格式.docx_第8页
第8页 / 共21页
c#连接数据库代码集合Word格式.docx_第9页
第9页 / 共21页
c#连接数据库代码集合Word格式.docx_第10页
第10页 / 共21页
c#连接数据库代码集合Word格式.docx_第11页
第11页 / 共21页
c#连接数据库代码集合Word格式.docx_第12页
第12页 / 共21页
c#连接数据库代码集合Word格式.docx_第13页
第13页 / 共21页
c#连接数据库代码集合Word格式.docx_第14页
第14页 / 共21页
c#连接数据库代码集合Word格式.docx_第15页
第15页 / 共21页
c#连接数据库代码集合Word格式.docx_第16页
第16页 / 共21页
c#连接数据库代码集合Word格式.docx_第17页
第17页 / 共21页
c#连接数据库代码集合Word格式.docx_第18页
第18页 / 共21页
c#连接数据库代码集合Word格式.docx_第19页
第19页 / 共21页
c#连接数据库代码集合Word格式.docx_第20页
第20页 / 共21页
亲,该文档总共21页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

c#连接数据库代码集合Word格式.docx

《c#连接数据库代码集合Word格式.docx》由会员分享,可在线阅读,更多相关《c#连接数据库代码集合Word格式.docx(21页珍藏版)》请在冰点文库上搜索。

c#连接数据库代码集合Word格式.docx

InitialCatalog=pubs;

UserId=sa;

Password=asdasd;

trustedConnection:

IntegratedSecurity=SSPI;

(useserverName\instanceNameasDataSourcetouseanspecifikSQLServerinstance,onlySQLServer2000)

oConn.Provider="

sqloledb"

connectviaanIPaddress:

DataSource=190.190.200.100,1433;

NetworkLibrary=DBMSSOCN;

UserID=sa;

(dbmssocn=tcp/ipinsteadofNamedPipes,attheendoftheDataSourceistheporttouse(1433isthedefault))

SqlConnection(.NET)

-or-

Trusted_Connection=False"

(boothconnectionstringsproducesthesameresult)

Trusted_Connection=True;

declaretheSqlConnection:

C#:

usingSystem.Data.SqlClient;

SqlConnectionoSQLConn=newSqlConnection();

oSQLConn.ConnectionString="

myconnectionstring"

;

oSQLConn.Open();

VB.NET:

ImportsSystem.Data.SqlClient

DimoSQLConnAsSqlConnection=NewSqlConnection()

oSQLConn.Open()

DataShape

msDataShape

Provider=MSDataShape;

DataProvider=SQLOLEDB;

wanttolearndatashaping?

Checkout4GuyfFromRolla'

sgreatarticleaboutDataShaping>

>

Readmore

Howtodefinewhichnetworkprotocoltouse

Example:

NameNetworklibrary

dbnmpntwWin32NamedPipes

dbmssocnWin32WinsockTCP/IP

dbmsspxnWin32SPX/IPX

dbmsvinnWin32BanyanVines

dbmsrpcnWin32Multi-Protocol(WindowsRPC)

importantnote!

WhenconnectingthroughtheSQLOLEDBproviderusethesyntaxNetworkLibrary=dbmssocn

andwhenconnectingthroughMSDASQLproviderusethesyntaxNetwork=dbmssocn

AllSqlConnectionconnectionstringproperties

ThistableshowsallconnectionstringpropertiesfortheADO.NETSqlConnectionobject.MostofthepropertiesarealsousedinADO.Allpropertiesanddescriptionsisfrommsdn.

NameDefaultDescription

ApplicationName 

Thenameoftheapplication,or'

.NetSqlClientDataProvider'

ifnoapplicationnameisprovided.

AttachDBFilename

-or-

extendedproperties

InitialFileName 

Thenameoftheprimaryfile,includingthefullpathname,ofanattachabledatabase.Thedatabasenamemustbespecifiedwiththekeyword'

database'

.

ConnectTimeout

ConnectionTimeout15Thelengthoftime(inseconds)towaitforaconnectiontotheserverbeforeterminatingtheattemptandgeneratinganerror.

ConnectionLifetime0Whenaconnectionisreturnedtothepool,itscreationtimeiscomparedwiththecurrenttime,andtheconnectionisdestroyedifthattimespan(inseconds)exceedsthevaluespecifiedbyconnectionlifetime.Usefulinclusteredconfigurationstoforceloadbalancingbetweenarunningserverandaserverjustbroughton-line.

ConnectionReset'

true'

Determineswhetherthedatabaseconnectionisresetwhenbeingremovedfromthepool.Settingto'

false'

avoidsmakinganadditionalserverround-tripwhenobtainingaconnection,buttheprogrammermustbeawarethattheconnectionstateisnotbeingreset.

CurrentLanguage 

TheSQLServerLanguagerecordname.

DataSource

Server

Address

Addr

NetworkAddress 

ThenameornetworkaddressoftheinstanceofSQLServertowhichtoconnect.

Enlist'

Whentrue,thepoolerautomaticallyenliststheconnectioninthecreationthread'

scurrenttransactioncontext.

InitialCatalog

Database 

Thenameofthedatabase.

IntegratedSecurity

Trusted_Connection'

Whethertheconnectionistobeasecureconnectionornot.Recognizedvaluesare'

'

and'

sspi'

whichisequivalentto'

MaxPoolSize100Themaximumnumberofconnectionsallowedinthepool.

MinPoolSize0Theminimumnumberofconnectionsallowedinthepool.

NetworkLibrary

Net'

dbmssocn'

ThenetworklibraryusedtoestablishaconnectiontoaninstanceofSQLServer.Supportedvaluesincludedbnmpntw(NamedPipes),dbmsrpcn(Multiprotocol),dbmsadsn(AppleTalk),dbmsgnet(VIA),dbmsipcn(SharedMemory)anddbmsspxn(IPX/SPX),anddbmssocn(TCP/IP).

ThecorrespondingnetworkDLLmustbeinstalledonthesystemtowhichyouconnect.Ifyoudonotspecifyanetworkandyouusealocalserver(forexample,"

."

or"

(local)"

),sharedmemoryisused.

PacketSize8192SizeinbytesofthenetworkpacketsusedtocommunicatewithaninstanceofSQLServer.

Password

Pwd 

ThepasswordfortheSQLServeraccountloggingon.

PersistSecurityInfo'

Whensetto'

security-sensitiveinformation,suchasthepassword,isnotreturnedaspartoftheconnectioniftheconnectionisopenorhaseverbeeninanopenstate.Resettingtheconnectionstringresetsallconnectionstringvaluesincludingthepassword.

Pooling'

Whentrue,theSQLConnectionobjectisdrawnfromtheappropriatepool,orifnecessary,iscreatedandaddedtotheappropriatepool.

UserID 

TheSQLServerloginaccount.

WorkstationIDthelocalcomputernameThenameoftheworkstationconnectingtoSQLServer.

note

Use;

toseparateeachproperty.

Ifanameoccursmorethanonce,thevaluefromthelastoneintheconnectionstringwillbeused.

Ifyouarebuildingyourconnectionstringinyourappusingvaluesfromuserinputfields,makesuretheusercan'

tchangetheconnectionstringbyinsertinganadditionalpropertywithanothervaluewithintheuservalue.

Access

Driver={MicrosoftAccessDriver(*.mdb)};

Dbq=C:

\mydatabase.mdb;

Uid=Admin;

Pwd=;

workgroup:

SystemDB=C:

\mydatabase.mdw;

exclusive:

Exclusive=1;

Uid=admin;

Pwd="

standardsecurity:

Provider=Microsoft.Jet.OLEDB.4.0;

DataSource=\somepath\mydb.mdb;

UserId=admin;

Password=;

workgroup(systemdatabase):

JetOLEDB:

SystemDatabase=system.mdw;

withpassword:

DatabasePassword=MyDbPassword;

Oracle

newversion:

Driver={MicrosoftODBCforOracle};

Server=OracleServer.world;

Uid=Username;

oldversion:

Driver={MicrosoftODBCDriverforOracle};

ConnectString=OracleServer.world;

Uid=myUsername;

Pwd=myPassword;

Provider=msdaora;

DataSource=MyOracleDB;

UserId=UserName;

thisone'

sfromMicrosoft,thefollowingarefromOracle

Provider=OraOLEDB.Oracle;

UserId=Username;

OSAuthent=1;

OracleConnection(.NET)

standard:

IntegratedSecurity=yes;

thisoneworksonlywithOracle8irelease3orlater

specifyingusernameandpassword:

UserId=username;

Password=passwd;

IntegratedSecurity=no;

declaretheOracleConnection:

usingSystem.Data.OracleClient;

OracleConnectionoOracleConn=newOracleConnection();

oOracleConn.ConnectionString="

oOracleConn.Open();

ImportsSystem.Data.OracleClient

DimoOracleConnAsOracleConnection=NewOracleConnection()

oOracleConn.Open()

missingtheSystem.Data.OracleClientnamespace?

Download.NETManagedProviderforOracle»

greatarticle!

"

FeaturesofOracleDataProviderfor.NET"

byRamaMohanG.atC#Corner

CoreLabsOraDirect(.NET)

UserID=scott;

Password=tiger;

Host=ora;

Pooling=true;

MinPoolSize=0;

MaxPoolSize=100;

ConnectionLifetime=0"

ReadmoreatCoreLabandtheproductpage.

msDataShape:

Provider=MSDataShape.1;

PersistSecurityInfo=False;

DataProvider=MSDAORA;

DataSource=orac;

userid=username;

password=mypw"

MySQL

odbc2.50Localdatabase:

Driver={mySQL};

Server=localhost;

Option=16834;

Database=mydatabase;

odbc2.50Remotedatabase:

Server=;

Port=3306;

Option=131072;

Stmt=;

Database

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2