获取可用 SQI 服务器的列表

Getting a list of available SQI servers

如何在本地网络(最好是主机名)上获取可用 Sql 服务器(或实例?)的列表。 大致是如何在DSN数据源设置中完成的: 图片:https://i.stack.imgur.com/ADM6w.png

这可以通过 Qt QProcess 和 windows 命令 SQLCMD 实现。

SQLCMD -L[c]

Lists the locally configured server computers, and the names of the server computers that are broadcasting on the network. This parameter cannot be used in combination with other parameters. The maximum number of server computers that can be listed is 3000.

.h

#include <QProcess>

private slots:
    void readResult();
private:
    QProcess getSQLNodes;

.cpp

 getSQLNodes.setProgram("SQLCMD");
 getSQLNodes.setArguments({"-Lc"});
 getSQLNodes.start();
 getSQLNodes.waitForStarted();
 connect(&getSQLNodes,&QProcess::readyRead, this, &MainWindow::readResult);

 void MainWindow::readResult()
 {
     while(getSQLNodes.bytesAvailable()){
     QString DSNservers =  getSQLNodes.readAll();
     qDebug() << DSNservers ;
     this->ui->plainTextEdit->appendPlainText(DSNservers);
     }
 }