c#连接数据库代码集合

上传人:人*** 文档编号:504353873 上传时间:2023-09-08 格式:DOC 页数:15 大小:71KB
返回 下载 相关 举报
c#连接数据库代码集合_第1页
第1页 / 共15页
c#连接数据库代码集合_第2页
第2页 / 共15页
c#连接数据库代码集合_第3页
第3页 / 共15页
c#连接数据库代码集合_第4页
第4页 / 共15页
c#连接数据库代码集合_第5页
第5页 / 共15页
点击查看更多>>
资源描述

《c#连接数据库代码集合》由会员分享,可在线阅读,更多相关《c#连接数据库代码集合(15页珍藏版)》请在金锄头文库上搜索。

1、SQLServerODBCstandardSecurity:Driver=SQLServer;Server=Aron1;Database=pubs;Uid=sa;Pwd=asdasd;trustedconnection:Driver=SQLServer;Server=Aron1;Database=pubs;Trusted_Connection=yes;promptforusernameandpassword:oConn.Properties(Prompt)=adPromptAlwaysoConn.OpenDriver=SQLServer;Server=Aron1;DataBase=pubs;O

2、LEDB,OleDbConnection(.NET)standardSecurity:Provider=sqloledb;DataSource=Aron1;InitialCatalog=pubs;UserId=sa;Password=asdasd;trustedConnection:Provider=sqloledb;DataSource=Aron1;InitialCatalog=pubs;IntegratedSecurity=SSPI;(useserverNameinstanceNameasDataSourcetouseanspecifikSQLServerinstance,onlySQLS

3、erver2000)promptforusernameandpassword:oConn.Provider=sqloledboConn.Properties(Prompt)=adPromptAlwaysoConn.OpenDataSource=Aron1;InitialCatalog=pubs;connectviaanIPaddress:Provider=sqloledb;DataSource=190.190.200.100,1433;NetworkLibrary=DBMSSOCN;lnitialCatalog=pubs;UserID=sa;Password=asdasd;(dbmssocn=

4、tcp/ipinsteadofNamedPipes,attheendoftheDataSourceistheporttouse(1433isthedefault)SqlConnection(.NET)standardSecurity:DataSource=Aron1;InitialCatalog=pubs;UserId=sa;Password=asdasd;-or-Server=Aron1;Database=pubs;UserID=sa;Password=asdasd;Trusted_Connection=False(boothconnectionstringsproducesthesamer

5、esult)trustedConnection:DataSource=Aron1;InitialCatalog=pubs;IntegratedSecurity=SSPI;-or-Server=Aron1;Database=pubs;Trusted_Connection=True;(boothconnectionstringsproducesthesameresult)(useserverNameinstanceNameasDataSourcetouseanspecifikSQLServerinstance,onlySQLServer2000)connectviaanIPaddress:Data

6、Source=190.190.200.100,1433;NetworkLibrary=DBMSSOCN;InitialCatalog=pubs;UserID=sa;Password=asdasd;(dbmssocn=tcp/ipinsteadofNamedPipes,attheendoftheDataSourceistheporttouse(1433isthedefault)declaretheSqlConnection:C#:usingSystem.Data.SqlClient;SqlConnectionoSQLConn=newSqlConnection();oSQLConn.Connect

7、ionString=myconnectionstring;oSQLConn.Open();VB.NET:ImportsSystem.Data.SqlClientDimoSQLConnAsSqlConnection=NewSqlConnection()oSQLConn.ConnectionString=myconnectionstringoSQLConn.Open()DataShapemsDataShapeProvider=MSDataShape;DataProvider=SQLOLEDB;DataSource=Aron1;lnitialCatalog=pubs;UserID=sa;Passwo

8、rd=asdasd;wanttolearndatashaping?Checkout4GuyfFromRollasgreatarticleaboutDataShapingReadmoreHowtodefinewhichnetworkprotocoltouseExample:Provider=sqloledb;DataSource=190.190.200.100,1433;NetworkLibrary=DBMSSOCN;InitialCatalog=pubs;UserID=sa;Password=asdasd;NameNetworklibrarydbnmpntwWin32NamedPipesdbm

9、ssocnWin32WinsockTCP/IPdbmsspxnWin32SPX/IPXdbmsvinnWin32BanyanVinesdbmsrpcnWin32Multi-Protocol(WindowsRPC)importantnote!WhenconnectingthroughtheSQLOLEDBproviderusethesyntaxNetworkLibrary=dbmssocnandwhenconnectingthroughMSDASQLproviderusethesyntaxNetwork=dbmssocnAllSqlConnectionconnectionstringproper

10、tiesThistableshowsallconnectionstringpropertiesfortheADO.NETSqlConnectionobject.MostofthepropertiesarealsousedinADO.Allpropertiesanddescriptionsisfrommsdn.NameDefaultDescriptionApplicationNameThenameoftheapplication,or.NetSqlClientDataProviderifnoapplicationnameisprovided.AttachDBFilename-or-extende

11、dproperties-or-InitialFileNameThenameoftheprimaryfile,includingthefullpathname,ofanattachabledatabase.Thedatabasenamemustbespecifiedwiththekeyworddatabase.ConnectTimeout-or-ConnectionTimeout15Thelengthoftime(inseconds)towaitforaconnectiontotheserverbeforeterminatingtheattemptandgeneratinganerror.Con

12、nectionLifetime0Whenaconnectionisreturnedtothepool,itscreationtimeiscomparedwiththecurrenttime,andtheconnectionisdestroyedifthattimespan(inseconds)exceedsthevaluespecifiedbyconnectionlifetime.Usefulinclusteredconfigurationstoforceloadbalancingbetweenarunningserverandaserverjustbroughton-Iine.Connect

13、ionResettrueDetermineswhetherthedatabaseconnectionisresetwhenbeingremovedfromthepool.Settingtofalseavoidsmakinganadditionalserverround-tripwhenobtainingaconnection,buttheprogrammermustbeawarethattheconnectionstateisnotbeingreset.CurrentLanguageTheSQLServerLanguagerecordname.DataSource-or-Server-or-A

14、ddress-or-Addr-or-NetworkAddressThenameornetworkaddressoftheinstaneeofSQLServertowhichtoconnect.EnlisttrueWhentrue,thepoolerautomaticallyenliststheconnectioninthecreationthreadscurrenttransactioncontext.InitialCatalog-or-DatabaseThenameofthedatabase.IntegratedSecurity-or-Trusted_ConnectionfalseWheth

15、ertheconnectionistobeasecureconnectionornot.Recognizedvaluesaretrue,false,andsspi,whichisequivalenttotrue.MaxPoolSize100Themaximumnumberofconnectionsallowedinthepool.MinPoolSize0Theminimumnumberofconnectionsallowedinthepool.NetworkLibrary-or-NetdbmssocnThenetworklibraryusedtoestablishaconnectiontoaninstanceofSQLServer.Supportedvaluesincludedbnmpntw(NamedPipes),dbmsrpcn(Multiprotocol),dbmsadsn(AppleTalk),dbmsgnet(VIA),dbmsipcn(SharedMemory)anddbmsspxn(IPX/SPX),anddbmssocn(TCP/IP).ThecorrespondingnetworkDLLmustbeinstalledonthesystemtowhichyouconnect.Ifyoudonotspecifyanetworkandyouu

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 活动策划

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号