本文主要是介绍数据库连接汇总 VS2005,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
微软提供了以下四种数据库连接方式:System.Data.OleDb.OleDbConnection
System.Data.SqlClient.SqlConnection
System.Data.Odbc.OdbcConnection
System.Data.OracleClient.OracleConnection
System.Data.OleDb.OleDbConnection
常用的一些连接字符串(C#代码):
OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\MyWeb\81\05\GrocerToGo.mdb");
OleDbConnection conn = new OleDbConnection(
@"Provider=Microsoft.Jet.OLEDB.4.0;Password=;
User ID=Admin;Data Source=grocertogo.mdb;");
OleDbConnection conn = new OleDbConnection(
"Provider=MSDAORA; Data Source=ORACLE8i7;Persist Security Info=False;Integrated Security=yes");
OleDbConnection conn = new OleDbConnection(
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\bin\LocalAccess40.mdb");
OleDbConnection conn = new OleDbConnection(
"Provider=SQLOLEDB;Data Source=MySQLServer;Integrated Security=SSPI");
System.Data.OracleClient.OracleConnection
常用的一些连接字符串(C#代码):
OracleConnection myConn = new System.Data.OracleClient.OracleConnection(
"Data Source=Oracle8i;Integrated Security=yes");
System.Data.Odbc.OdbcConnection
常用的一些连接字符串(C#代码):
OdbcConnection conn = new OdbcConnection(
"Driver={SQL Server};Server=MyServer;Trusted_Connection=yes;Database=Northwind;");
OdbcConnection conn = new OdbcConnection(
"Driver={Microsoft ODBC for Oracle};Server=ORACLE8i7;
Persist Security Info=False;Trusted_Connection=yes");
OdbcConnection conn = new OdbcConnection(
"Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\bin\nwind.mdb");
OdbcConnection conn = new OdbcConnection(
"Driver={Microsoft Excel Driver (*.xls)};DBQ=c:\bin\book1.xls");
OdbcConnection conn = new OdbcConnection(
"Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=c:\bin");
OdbcConnection conn = new OdbcConnection("DSN=dsnname");
其他厂商提供的数据库连接:
DB2Connection myConn = new IBM.Data.DB2.DB2Connection(
"DATABASE = SAMPLE;UID=; PWD=;");
DB2Connection myConn = new IBM.Data.DB2.DB2Connection("DATABASE = SAMPLE");
BdpConnection myConn = new Borland.Data.Provider.BdpConnection("assembly=Borl
and.Data.Mssql,Version=1.1.0.0,Culture=neutral,PublicKeyToken=91d62ebb5b0d1b1b;ve
ndorclient=sqloledb.dll;osauthentication=False;database=;usernam
e=;hostname=;password=;provider=MSSQL");
BdpConnection myConn = new Borland.Data.Provider.BdpConnection("assembly=Borl
and.Data.Db2,Version=1.1.0.0,Culture=neutral,PublicKeyToken=91d62ebb5b0d1b1b;ve
ndorclient=db2cli.dll;database=;username=;
password=;provider=DB2");
System.Data.SqlClient.SqlConnection
常用的一些连接字符串(C#代码):
SqlConnection conn
= new SqlConnection( "Server=(local);Integrated Security=SSPI;database=Pubs");
SqlConnection conn
= new SqlConnection("server=(local)\\NetSDK;database=pubs;Integrated Security=SSPI");
SqlConnection conn = new SqlConnection(
"Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;");
SqlConnection conn = new SqlConnection(
" data source=(local);initial catalog=xr;integrated security=SSPI;
persist security info=False;workstation id=XURUI;packet size=4096; ");
SqlConnection myConn = new
System.Data.SqlClient.SqlConnection("Persist Security Info=False;Integrated
Security=SSPI;database=northwind;server=mySQLServer");
SqlConnection conn = new SqlConnection(
" uid=sa;pwd=passwords;initial catalog=pubs;data source=127.0.0.1;Connect Timeout=900");
自己遇到的连接字符串
连接Access
web.config文件
Window身份登陆
providerName="System.Data.SqlClient" />
连接oracle
string constring = "Data Source=MYORACLE;User=system; Password=system";
OracleConnection oraconn = new OracleConnection(constring);
远程连接oracle
string constring = "Data Source=(DESCRIPTION = (ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 211.82.196.69)(PORT = 1521)) )(CONNECT_DATA =(SID = orcl)));Persist Security Info=True;User=system; Password=system";
OracleConnection oraconn = new OracleConnection(constring);
Microsoft Visual Basic 连接sql server2005
无源数据库连接(Visual Basic 6.0)
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
建立无源数据库连接
conn.ConnectionString = "driver=SQL Server;server=.;uid=sa;pwd=123123123;Database=test"
//这里的driver是SQL Server Configuration Manager 中SQL Server 2005 服务中的SQL Server(MSSQLSERVER)
conn.ConnectionTimeout = 50
conn.Open
Dim str As String
连接连接对象
Set rs.ActiveConnection = conn
设置游标类型
rs.CursorType = adOpenDynamic
设置查询字符串
str = "select * from student where id=7"
rs.Open str
Text1.Text = rs.Fields("name")
Vb.net 连接数据库
连接oracle
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As OracleConnection = New OracleConnection()
conn.ConnectionString = "server=stylar;uid=stylar;pwd=stylar"
conn.Open()
Dim str As String
Dim oda As OracleDataAdapter
str = "select * from classinfo"
oda = New OracleDataAdapter(str, conn)
Dim ds As DataSet = New DataSet()
oda.Fill(ds, "classinfo")
dgv1.DataSource = ds
dgv1.DataMember = "classinfo"
End Sub"
连接sql server
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim conn As SqlConnection = New SqlConnection()
conn.ConnectionString = "server=.;database=PaperOnlineInstruct;uid=sa;pwd=123"
Dim str As String = "select * from putinvitation"
Dim sda As SqlDataAdapter = New SqlDataAdapter()
sda = New SqlDataAdapter(str, conn)
Dim ds As DataSet = New DataSet()
sda.Fill(ds, "classinfo")
dgv1.DataSource = ds
dgv1.DataMember = "classinfo"
这篇关于数据库连接汇总 VS2005的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!