繁体   English   中英

在未安装SQL Server Management Studio的情况下运行C#应用程序

[英]Run C# application without SQL Server Management Studio installed

我已经使用C#.net创建了一个简单的登录应用程序。

我创建了数据库test在其中创建了名为login表。

表: Login包含:

create table login
(
    name varchar(20),
    pass varchar(20) 
)

这是我在C#.net中编写的登录按钮代码:

private void BtnLogin_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection();

        con.ConnectionString = "Data Source=ServerName;Initial Catalog=test;Integrated Security=True";

        con.Open();

        SqlDataReader dr = null;

        SqlCommand cmd = new SqlCommand("Select * from login", con);

        dr = cmd.ExecuteReader();

        int count = 0;

        while (dr.Read())
        {
            if (textBox1.Text == dr[0].ToString() && textBox2.Text == dr[1].ToString())
            {
                count = count + 1;
            }
            else
            {
                count = count + 0;
            }
        }

        if (count == 1)
        {
            MessageBox.Show("Success");
        }
        else
        {
            MessageBox.Show("Fail");
        }

    }

注意 :如果我在一台计算机上安装了Visual Studio 2010和SQL Server Management Studio,则上面的示例对我来说效果很好。

我想在仅安装Visual Studio 2010而不是SQL Server Management Studio的计算机上运行上述应用程序。

可能吗?

Data Source=ServerName;Initial Catalog=test;Persist Security Info=True;User ID=YourUserId;Password=YourPassword

另外,您还必须在本地计算机上安装.net框架

您正在使用的SqlClient类型(SqlConnection,SqlDataReader等)在System.Data.dll中定义(您可以通过转到MSDN文档来查看,该程序集仅在“ Syntax”大标题的上方记录)。这是.NET Framework的一部分。 因此,只要在计算机上安装了.NET Framework,就不需要任何其他依赖项,例如Visual Studio或SSMS。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM