繁体   English   中英

C#中的OLEDB连接问题

[英]OLEDB Connection problem in C#

我正在使用C#Windows应用程序,并且遇到OLEDB与SQL SERVER 2008的连接问题,我的代码太简单了:我正在尝试从此查询填充datagridview

string connString = "Provider=SQLOLEDB;Data Source=servername;Initial Catalog=DBname;Integrated Security=SSPI";

        string query = "SELECT * FROM account";

        //create an OleDbDataAdapter to execute the query
        OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);

        //create a command builder
        OleDbCommandBuilder cBuilder = new OleDbCommandBuilder(dAdapter);

        //create a DataTable to hold the query results
        DataTable dTable = new DataTable();

        //fill the DataTable
        dAdapter.Fill(dTable);

        //the DataGridView
        //DataGridView dgView = new DataGridView();

        //BindingSource to sync DataTable and DataGridView
        BindingSource bSource = new BindingSource();

        //set the BindingSource DataSource
        bSource.DataSource = dTable;

        //set the DataGridView DataSource
        dataGridView_FraudDetails.DataSource = bSource;
        dAdapter.Update(dTable);

但我在这一行中收到以下错误

//fill the DataTable
        dAdapter.Fill(dTable);

“ [DBNETLIB] [ConnectionOpen(Connect())。] SQL Server不存在或访问被拒绝。 代码运行良好,但是当我卸载服务器并再次重新安装时,它给了我这个错误

我试图关闭防火墙,但是它没有任何建议

您正在使用SQL Server Express吗? 如果是这样,则需要确保将其配置为接受通过TCP / IP或命名管道的连接。 默认情况下,SQL Server Express不接受连接。 请参阅http://www.datamasker.com/SSE2005_NetworkCfg.htm (此页面特定于SQL Server 2005,但也应适用于2008)。

转到“ SQL Server配置管理器”(在“开始”菜单中的“所有程序”>“ Microsoft SQL Server”下),并为您的实例确保启用了TCP / IP。 默认情况下,对于新安装的SQL Server禁用此功能。

暂无
暂无

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

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