关闭

vs2005下怎么连接sql server 2000

标签: sql serverdatasetstringsqlserver数据库security
2127人阅读 评论(1) 收藏 举报
怎么连接不上啊,事件探查器显示也没有连接,是不是要修改默认配置,怎么改啊。
跟以前一样连
刚用
string conn = "server = (local);database = Text;User Id = sa;pwd=";
string sqlContent = "select * from PersonInfo";
SqlConnection myConnection = new SqlConnection(conn);
SqlCommand myCommand = new SqlCommand(sqlContent, myConnection);
myConnection.Open();
SqlDataReader myDataReader = myCommand.ExecuteReader();
if (myDataReader.Read())
{
this.Label1.Text = myDataReader.GetString(1);
}
myConnection.Close();
就能取出数据。
但用
string con = "Data Source=(local);Initial Catalog=Text;User Id = sa;pwd=";
string sql = "select * from PersonInfo";
SqlConnection sqlconn = new SqlConnection(con);
SqlDataAdapter sqldadt = new SqlDataAdapter(sql, sqlconn);
//sqlconn.Open();
DataSet ds = new DataSet("list");
sqldadt.Fill(ds);
sqlconn.Close();
this.DataList1.DataSource = ds;
DataList1.DataBind();
执行到SqlDataAdapter sqldadt = new SqlDataAdapter(sql, sqlconn);就过不去了。

数据库连接字符串的写法:
以下就是进行数据库的连接,由于ADO支持的数据库种类繁多,因此连接也相当复杂。从连接类型可以分为两种:1.采用连接字符串;2.使用UDL文件。对于每种方法又有不同的写法。
①.连接字符串
===>Access Connect String
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=dbtest.mdb
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=dbTest.mdb;Jet OLEDB:Database Password=********;");
===>SQLServer Connect String
Driver=SQL Server;Database=fwbmk;Server=127.0.0.1;UID=sa;PWD=xx; (自带)
使用标准安全级别:
strConnect = _T("Provider=sqloledb;Data Source=MyServerName;Initial Catalog=MyDatabaseName;User Id=MyUsername;Password=MyPassword;");
使用信任连接:
strConnect = _T("Provider=sqloledb;Data Source=MyServerName;Initial Catalog=MyDatabaseName;Integrated Security=SSPI;");
指定SQLServer实例:
strConnect = _T("Provider=sqloledb;Data Source=MyServerName/MyInstanceName;Initial Catalog=MyDatabaseName;User Id=MyUsername;Password=MyPassword;");
本地数据库:
strConnect = _T("Provider=sqloledb;Data Source=(local);Initial Catalog=myDatabaseName;User ID=myUsername;Password=myPassword;");
网络数据库:
strConnect = _T("Provider=sqloledb;Network Library=DBMSSOCN;Data Source=130.120.110.001,1433;Initial Catalog=MyDatabaseName;User
3
计算机软件技术《数据库部分》——ADO开发应用程序ID=MyUsername;Password=MyPassword;");
===>Oracle Connect String
微软提供的Oracle标准连接是:
strConnect = _T("Provider=MSDAORA;Data Source=serverName;User ID=userName; Password=userPassword;");
Oracle公司提供的连接方式:
使用标准安全级别:
strConnect = _T("Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;User Id=myUsername;Password=myPassword;");
使用信任连接
1.strConnect = _T("Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;User Id=/;Password=;"); UID为'/'
2.strConnect = _T("Provider=OraOLEDB.Oracle;Data Source=MyOracleDB;OSAuthent=1;");使用OSAuthent=1
对于连接字符串可以参考以下网页: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdreforacleprovspec.asp?frame=true
http://download-west.oracle.com/otndoc/oracle9i/901_doc/win.901/a90171/using.htm
===>ODBC 配置数据源
strConnect = _T("DSN=ADOTest");



我c#里用这些代码连接

用了一个下拉列表框.绑定了users表的userid 列如下




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;

using System.Drawing;
using System.Text;
using System.Windows.Forms;


namespace WindowsApplication1
{
public partial class Form1 : Form


{
private DataSet ds;

public Form1()
{
InitializeComponent();


}

private void Form1_Load(object sender, EventArgs e)

{
OleDbConnection dbcon = new OleDbConnection();

dbcon.ConnectionString = "Provider=SQLOLEDB.1;Password=hw;Persist Security Info=True;User ID=sa;Initial Catalog=eugame;Data Source=127.0.0.1";
dbcon.Open();

ds = new DataSet();

OleDbDataAdapter rsread = new OleDbDataAdapter("select * from users",dbcon);
rsread.Fill(ds,"users");
textBox1.DataBindings.Add("text",ds,"users.name");

comboBox1.DataSource = ds;
comboBox1.DisplayMember = "users.userid";
comboBox1.ValueMember = "users.userid";

dbcon.Close();



}



}
}
没有区别的啊
学习着!
http://community.csdn.net/Expert/topic/4922/4922102.xml?temp=.3190119
与VB6.0 、2003一样


可以在web.config里面设置
string con = "Data Source=(local);Initial Catalog=Text;User Id = sa;pwd=";
string sql = "select * from PersonInfo";
SqlConnection sqlconn = new SqlConnection(con);
SqlDataAdapter sqldadt = new SqlDataAdapter(sql, sqlconn);
//sqlconn.Open();
DataSet ds = new DataSet("list");
sqldadt.Fill(ds);
sqlconn.Close();
this.DataList1.DataSource = ds;
DataList1.DataBind();

你认证改为windows认证,Data Source=(local);Initial Catalog=Text;integrated security = true"; 
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:177767次
    • 积分:3037
    • 等级:
    • 排名:第11493名
    • 原创:107篇
    • 转载:88篇
    • 译文:0篇
    • 评论:28条
    最新评论