c# - 无密码进入SQL Server

标签 c# sql-server

enter image description here

上面的输出是从下面的代码生成的:

using System.Windows.Forms;
using Microsoft.SqlServer.Management.Smo;

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
       DataTable dataTable = SmoApplication.EnumAvailableSqlServers(true);
       listBox1.ValueMember = "Name";
       listBox1.DataSource = dataTable;
    }

    private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        listBox2.Items.Clear();
        if (listBox1.SelectedIndex != -1)
        {
            string serverName = listBox1.SelectedValue.ToString();
            Server server = new Server(serverName);
            try
            {
                foreach (Database database in server.Databases)
                {
                    listBox2.Items.Add(database.Name);
                }
            }
            catch (Exception ex)
            {
                string exception = ex.Message;
            }
        }
    }
}

这对我来说很奇怪。

这段代码如何能够在不要求用户名和密码的情况下进入 SQL Server?

最佳答案

SMO 默认使用 Windows 身份验证,因此您当前的 Windows 凭据用于连接。

关于c# - 无密码进入SQL Server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50311138/

相关文章:

c# - 如何通过 COM 公开可空类型

c# for 循环错误的迭代次数

c# - 从 ModelState 中删除 JSON.net 序列化异常

c# - 如何在Cassandra中使用 ‘Wide Column’功能?

mysql - SQL 检查某个值是否存在于任何列中并返回另一列列出的值

sql - tsql : How to retrieve the last date of each month between given date range

c# - MSDN 上 SimplePriorityQueue 示例中的严重错误

sql-server - 阿拉伯字符串上的 WHERE 子句匹配问题

SQL:选择尚不存在的最小值

sql-server - 死锁的历史