这个问题与这个先前的SO问题有关
我已经修复了程序中使用的字符串,所以它现在运行那行代码。
为什么下面的失败就行myAdapt.Fill(mySet, "AvailableValues");
了,有错误SQLException was Unhandled; A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections
数据库是项目的一部分,那么为什么连接会有困难呢?
- 我试过在 sql 文件中运行 sql 字符串,它运行正常。
我尝试从 DGV 中删除所有列。
void PopulateGridView() { SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DatabaseDGVexperiments.Properties.Settings.DatabaseDGVexperimentsConnStg"].ConnectionString); SqlDataAdapter myAdapt = new SqlDataAdapter("SELECT refText FROM helloworld", conn); DataSet mySet = new DataSet(); myAdapt.Fill(mySet, "AvailableValues"); DataTable myTable = mySet.Tables["AvailableValues"]; this.uxExperimentDGV.DataSource = myTable; }