連接到SQL Server數據庫中,我曾嘗試與下面的代碼:無法從代碼
private void button2_Click(object sender, EventArgs e)
{
string connString = @"Server=localhost;Initial Catalog=Database2;User id=***;Password=***;";
SqlConnection sqlConn = new SqlConnection(connString);
string sqlQuery = @"SELECT * from tableP";
SqlCommand cmd = new SqlCommand(sqlQuery, sqlConn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable table = new DataTable();
da.Fill(table);
DataGridView dgv = new DataGridView();
dgv.DataSource = new BindingSource(table, null);
}
其他信息:
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. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
你甚至不問一個問題,你剛纔向我們扔代碼,並希望我們解決這個問題。 –
親愛的請不要將您的憑證暴露給外界。我已經編輯它。 –
嗨,你可以嘗試與其他連接字符串與SQLServer在https://www.connectionstrings.com/sql-server-2008/ –