using System;
using System.Data;
using System.Data.SqlClient;namespace ConsoleApplication22
{

class Class1
{

static void Main(string[] args)
{
SqlConnection thisConnection=new SqlConnection(@"Data Source=hitler;Integrate Security=SSPI;"
+"Initial Catalog=hotel");
thisConnection.Open();
SqlCommand thisCommand=thisConnection.CreateCommand();
thisCommand.CommandText="SELECT CID,RID from CheckIn ";
SqlDataReader thisReader=thisCommand.ExecuteReader();
while(thisReader.Read())
 {
Console.WriteLine("\t{0}\t{1}",thisReader["CID"],thisReader["RID"]);
             }
thisReader.Close();
thisConnection.Close(); }
}
}
服务器hitler
服务 SQL server
好像没密码
程序编译没通过...
谁帮忙看看哪里出错了我是要使用hotel 数据库下表CheckIn中的RID.CID项..

解决方案 »

  1.   

    未处理的“System.ArgumentException”类型的异常出现在 system.data.dll 中。其他信息: 不支持关键字: “integrate security”。出错提示
      

  2.   

    连接字符串不支持“integrate security”,换个别的
      

  3.   

    改成这样试试:Initial Catalog=Northwind;Data Source=localhost;Integrated Security=SSPI;
      

  4.   

    (@"Data Source=hitler;Integrate Security=SSPI;"
    +"Initial Catalog=hotel");
    ("Data Source=hitler;Integrated Security=SSPI;"
    +"Initial Catalog=hotel");
      

  5.   

    这样写也可以:
    SqlConnection thisConnection=new SqlConnection("Server=localhost;uid=sa;pwd=;database=hotel");
      

  6.   

    sql server自带的一个数据库
      

  7.   

    用jxufewbt(我的目标是5星) 的
      

  8.   

    SqlConnection thisConnection=new SqlConnection("Server=localhost;uid=sa;pwd=;database=hotel");后运行是可以了.但是不能显示任何东西
      

  9.   

    连接数据库的语句,参考参考using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;namespace ManagePlam
    {
    /// <summary>
    /// WebForm1 的摘要说明。
    /// </summary>
    public class index : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.Label Label1;
    protected System.Web.UI.WebControls.TextBox TextBox1;
    protected System.Web.UI.WebControls.Label Label2;
    protected System.Web.UI.WebControls.TextBox TextBox2;
    protected System.Web.UI.WebControls.Label Label3;
    protected System.Web.UI.WebControls.TextBox username;
    protected System.Web.UI.WebControls.TextBox password;
    protected System.Web.UI.WebControls.Button Button1;
    protected System.Web.UI.WebControls.Image Image1;
    protected System.Web.UI.WebControls.TextBox Vcode;
    protected System.Web.UI.WebControls.Label lblShow;
    protected System.Web.UI.WebControls.TextBox TextBox3;
    private void Button1_Click(object sender, System.EventArgs e)
    {
    //连接数据库字符串
    string ConnectionString = "Server=(local);User id=all;Pwd=all;Database=net_testlog";
    string Sql = "SELECT * FROM ALLUSER WHERE username='"+username+"'";
    //创建SqlConnection对象
    SqlConnection Connection = new SqlConnection(ConnectionString); 
    //创建SqlCommand对象
    SqlCommand Command = new SqlCommand(Sql,Connection);
    //打开数据库对CommandText属性赋值
    //Command.Connection = Connection;
    //Command.CommandText = "SELECT password  FROM ALLUSER where username='username'";
    //指定命令类型是SQL语句
    Command.CommandType = CommandType.Text;
         
    try
    {
    //打开数据库
    //Connection.Open();
    //打开数据库连接
    Command.Connection.Open();
    //Response.Write ("数据库连接成功");
    //获取查询结果
    object test = Command.ExecuteScalar();
    //Response.Write (test);
    //执行SQL语句返回DataReader对象
    SqlDataReader dr = Command.ExecuteReader();
    while(dr.Read())
    {
    string strpassword = dr["password"].ToString ();//强制转换成STRING型数据
    Response.Write (strpassword);

    if (password==strpassword)
    {
    Response.Write ("ok");
    }
    else 
    {
    string message = ("对不起,您输入的内容有误!");
                                              Response.Redirect ("index.aspx?MSG=" + message ); 
    } }
    //关闭 DataReader
    dr.Close();

    }
    catch(SqlException ex)
    {
    //Response.Write ("数据库连接失败");
    //Response.Write (ex);
    }
    finally
    {
    //关闭数据库
    Connection.Close();
    //关闭数据库连接
    Command.Connection.Close(); }
    }
    }
    }
      

  10.   

    open()了没有出现异常基本就是连接成功了,如果连接不成功会报错吧
      

  11.   

    到桌面上建一个文本文件,把扩展名改为ubl,然后双击,去操作,然后你再以txt的方式打开文件,你会发现里面保存了你所要的一切连接信息.不用到处查了.
      

  12.   

    并天雪地裸体求问把localhost改成hitler就好了..UID=sa pwd=
    为什么啊
      

  13.   

    try
                                     {
       
                                     }
                                   catch(Exception _e)
    {
    string a=_e.Message;
    return new DataTable();
    }
    finally
    {
    con.Close();
    }
      

  14.   


    学习中.----------------------------------------------------------------
    http://wbweir.anyp.cn/
    为神六喝彩,向所有科技工作者致敬!
    拒绝日货。