现在的位置: 首页 > 综合 > 正文

.net sql连接字符串

2013年07月13日 ⁄ 综合 ⁄ 共 3750字 ⁄ 字号 评论关闭
 

  • Application Name(应用程序名称):应用程序的名称。如果没有被指定的话,它的值为.NET SqlClient Data Provider(数据提供程序).
  • AttachDBFilenameextended properties(扩展属性)/Initial File Name(初始文件名):可连接数据库的主要文件的名称,包括完整路径名称。数据库名称必须用关键字数据库指定。
  • Connect Timeout(连接超时)/Connection Timeout(连接超时):一个到服务器的连接在终止之前等待的时间长度(以秒计),缺省值为15。
  • Connection Lifetime(连接生存时间):当一个连接被返回到连接池时,它的创建时间会与当前时间进行对比。如果这个时间跨度超过了连接的有效期的话,连接就被取消。其缺省值为0。
  • Connection Reset(连接重置):表示一个连接在从连接池中被移除时是否被重置。一个伪的有效在获得一个连接的时候就无需再进行一个额外的服务器来回运作,其缺省值为真。
  • Current Language(当前语言):SQL Server语言记录的名称。
  • Data Source(数据源)/Server(服务器)/Address(地址)/Addr(地址)/Network Address(网络地址):SQL Server实例的名称或网络地址。
  • Encrypt(加密):当值为真时,如果服务器安装了授权证书,SQL Server就会对所有在客户和服务器之间传输的数据使用SSL加密。被接受的值有true(真)、false(伪)、yes(是)和no(否)。
  • Enlist(登记):表示连接池程序是否会自动登记创建线程的当前事务语境中的连接,其缺省值为真。
  • Database(数据库)/Initial Catalog(初始编目):数据库的名称。
  • Integrated Security(集成安全)/Trusted Connection(受信连接):表示Windows认证是否被用来连接数据库。它可以被设置成真、伪或者是和真对等的sspi,其缺省值为伪。
  • Max Pool Size(连接池的最大容量):连接池允许的连接数的最大值,其缺省值为100。
  • Min Pool Size(连接池的最小容量):连接池允许的连接数的最小值,其缺省值为0。
  • Network Library(网络库)/Net(网络):用来建立到一个SQL Server实例的连接的网络库。支持的值包括: dbnmpntw (Named Pipes)、dbmsrpcn (Multiprotocol/RPC)、dbmsvinn(Banyan Vines)、dbmsspxn (IPX/SPX)和dbmssocn (TCP/IP)。协议的动态链接库必须被安装到适当的连接,其缺省值为TCP/IP。
  • Packet Size(数据包大小):用来和数据库通信的网络数据包的大小。其缺省值为8192。
  • Password(密码)/Pwd与帐户名相对应的密码。
  • Persist Security Info(保持安全信息):用来确定一旦连接建立了以后安全信息是否可用。如果值为真的话,说明像用户名和密码这样对安全性比较敏感的数据可用,而如果值为伪则不可用。重置连接字符串将重新配置包括密码在内的所有连接字符串的值。其缺省值为伪。
  • Pooling(池):确定是否使用连接池。如果值为真的话,连接就要从适当的连接池中获得,或者,如果需要的话,连接将被创建,然后被加入合适的连接池中。其缺省值为真。
  • User ID(用户ID):用来登陆数据库的帐户名。
  • Workstation ID(工作站ID):连接到SQL Server的工作站的名称。其缺省值为本地计算机的名称。
Standard Security:
使用 SQL Server 身份验证:
"Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd;"
   - or -
"Server=Aron1;Database=pubs;User ID=sa;Password=asdasd;Trusted_Connection=False"

Trusted Connection:
使用 Windows 身份验证(信任连接):

"Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;"
   - or -
"Server=Aron1;Database=pubs;Trusted_Connection=True;"

Connect via an IP address:
"Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=pubs;User ID=sa;Password=asdasd;"

Enabling MARS (multiple active result sets):
仅仅支持 ADO.NET2.0

"Server=Aron1;Database=pubs;Trusted_Connection=True;MultipleActiveResultSets=true" 

    Note! Use ADO.NET 2.0 for MARS functionality. MARS is not supported in ADO.NET 1.0 nor ADO.NET 1.1
    Streamline your Data Connections by Moving to MARS, by Laurence Moroney, DevX.com >>

Attach a database file on connect to a local SQL Server Express instance:

"Server=./SQLExpress;AttachDbFilename=c:/asd/qwe/mydbfile.mdf;Database=dbname;Trusted_Connection=Yes;"
   - or -
"Server=./SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;Database=dbname;Trusted_Connection=Yes;"
   (use |DataDirectory| when your database file resides in the data directory) 
    
            Why is the "Database" parameter needed? Answer: If the database was previously attached, SQL Server does not reattach it (it uses the attached database as the default for the connection).

Using "User Instance" on a local SQL Server Express instance:

"Data Source=./SQLExpress;integrated security=true;attachdbfilename=|DataDirectory|/mydb.mdf;user instance=true;" 

        The "User Instance" functionality creates a new SQL Server instance on the fly during connect. This works only on a local SQL Server 2005 instance and only when connecting using windows authentication over local named pipes. The purpose is to be able to create a full rights SQL Server instance to a user with limited administrative rights on the computer. To enable the functionality: sp_configure 'user instances enabled','1' (0 to disable)

        Using SQL Server 2005 Express? Don't miss the server name syntax: SERVERNAME/SQLEXPRESS (Substitute "SERVERNAME" with the name of the computer)

如果要进行同步/异步访问需要在字符串后面继续添加 Asynchronous Processing=true 默认关闭

如果要开启 MARS 则加上 MultipleActiveResultSets=True 默认开启。

更多的可以访问:http://www.connectionstrings.com/

 
摘自

抱歉!评论已关闭.