爱和自由 | 周易 | 股票入门 | 经典小故事 | 技术分享 | 笑笑事 | 个人成长 |

2009 1.8 Thu
    123
45678910
11121314151617
18192021222324
25262728293031
«» 2009 - 1 «»

搜索BLOG文章

 

博客基本信息
用户名: 老马嗖嗖
等级: 一星会员
威望: 103.2
金钱: 7955
在线时间: 1108 分钟
日志总数: 232
评论数量: 152
访问次数: 1082537
建立时间: 2006-06-03
韩寒  金庸  刘德华    火锅  银色  《武林外传》  《加勒比海盗》  古典音乐  乡村音乐  游泳  心理测试 


XML RSS 2.0 WAP



作者: 老马嗖嗖   发表日期: 2007-08-09
复制  400电话申请,只要800元


TAG: 收藏 推荐
  •  SQL Native Client OLE DB Provider
    •  Standard security:
"Provider=SQLNCLI;Server=Aron1;Database=pubs;UID=myUsername;PWD=myPassword;"
 
    •  Trusted connection:
"Provider=SQLNCLI;Server=Aron1;Database=pubs;Trusted_Connection=yes;"
Equivalents
Integrated Security=SSPI equals Trusted_Connection=yes
    •  Prompt for username and password:
oConn.Properties("Prompt") = adPromptAlways
oConn.Open "Provider=SQLNCLI;Server=Aron1;DataBase=pubs;"
 
    •  Enabling MARS (multiple active result sets):
"Provider=SQLNCLI;Server=Aron1;Database=pubs;Trusted_Connection=yes;MarsConn=yes"
Equivalents
MarsConn=yes equals MultipleActiveResultSets=true equals MARS_Connection=yes

Using MARS with SQL Native Client, by Chris Lee >>
    •  Encrypt data sent over network:
"Provider=SQLNCLI;Server=Aron1;Database=pubs;Trusted_Connection=yes;Encrypt=yes"
 
    •  Attach a database file on connect to a local SQL Server Express instance:
"Provider=SQLNCLI;Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf;Database=dbname;Trusted_Connection=Yes;"
   - or -
"Provider=SQLNCLI;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).
Download the SQL Native Client here >> (the package contains booth the ODBC driver and the OLE DB provider)
Using SQL Server 2005 Express? Don't miss the server name syntax: SERVERNAME\SQLEXPRESS (Substitute "SERVERNAME" with the name of the computer)
  •  SqlConnection (.NET)
    •  Standard Security:
"Data Source=Aron1;Initial Catalog=pubs;User Id=myUsername;Password=myPassword;"
   - or -
"Server=Aron1;Database=pubs;User ID=myUsername;Password=myPassword;Trusted_Connection=False"
   (both 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;"
   (both connection strings produces the same result)
(use serverName\instanceName as Data Source to use an specifik SQLServer instance)
    •  Connect via an IP address:
      "Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=pubs;User ID=myUsername;Password=myPassword;"
(DBMSSOCN=TCP/IP instead of Named Pipes, at the end of the Data Source is the port to use (1433 is the default))
    •  Enabling MARS (multiple active result sets):
"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)
  •  Context Connection - connecting to "self" from within your CLR stored prodedure/function
    •  C#:
using(SqlConnection connection = new SqlConnection("context connection=true"))
{
    connection.Open();
    // Use the connection
}
 
    •  Visual Basic:
Using connection as new SqlConnection("context connection=true")
    connection.Open()
    ' Use the connection
End Using
 
The context connection lets you execute Transact-SQL statements in the same context (connection) that your code was invoked in the first place.
  •  Read more
    •  When to use SQL Native Client?
      •  .Net applications
Do not use the SQL Native Client. Use the .NET Framework Data Provider for SQL Server (SqlConnection).
      •  COM applications, all other then .Net applications
Use the SQL Native Client if you are accessing an SQL Server 2005 and need the new features of SQL Server 2005 such as MARS, encryption, XML data type etc. Continue use your current provider (OLE DB / ODBC through the MDAC package) if you are not connecting to an SQL Server 2005 (that's quite obvious eh..) or if you are connecting to an SQL Server 2005 but are not using any of the new SQL Server 2005 features.
For more details on the differences between MDAC and SQL Native Client, read this msdn article >>
·  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=myUsername;Pwd=myPassword;"
 
    •  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=myUsername;Password=myPassword;"
This one's from Microsoft, the following are from Oracle
    •  Standard Security:
"Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;User Id=myUsername;Password=myPassword;"
 
    •  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=myUsername;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 connection string";
oOracleConn.Open();
 
VB.NET:
Imports System.Data.OracleClient
Dim oOracleConn As OracleConnection = New OracleConnection()
oOracleConn.ConnectionString = "my connection string"
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=myUsername;password=myPassword"
Want to learn data shaping? Check out 4GuyfFromRolla's great article about Data Shaping >>
·  MySQL
  •  MyODBC
    •  MyODBC 2.50 Local database:
"Driver={mySQL};Server=localhost;Option=16834;Database=mydatabase;"
 
    •  MyODBC 2.50 Remote database:
"Driver={mySQL};Server=data.domain.com;Port=3306;Option=131072;Stmt=;Database=my-database;Uid=myUsername;Pwd=myPassword;"
 
    •  MyODBC 3.51 Local database:
"DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=myDatabase;USER=myUsername;PASSWORD=myPassword;OPTION=3;"
 
    •  MyODBC 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=myUsername;Password=myPassword;"
  •  Connector/Net 1.0 (.NET)
    •  Standard:
"Server=Server;Database=Test;Uid=myUsername;Pwd=myPassword;"
Download the driver at MySQL Developer Zone.
    •  Specifying port:
"Server=Server;Port=1234;Database=Test;Uid=myUsername;Pwd=myPassword;"
Default port is 3306. Enter value -1 to use a named pipe connection.
    •  Declare the MySqlClient connection:
C#:
using MySql.Data.MySqlClient;
MySqlConnection oMySqlConn = new MySqlConnection();
oMySqlConn.ConnectionString = "Server=Server;Database=Test;Uid=myUsername;Pwd=myPassword;";
oMySqlConn.Open();
 
VB.NET:
Imports MySql.Data.MySqlClient
Dim oMySqlConn As MySqlConnection = New MySqlConnection()
oMySqlConn.ConnectionString = "Server=Server;Database=Test;Uid=myUsername;Pwd=myPassword;"
oMySqlConn.Open()
 




文章评论0条回复