在Ado.net中打开连接时出错 [英] Error while Opening the connnetion in Ado.net

查看:97
本文介绍了在Ado.net中打开连接时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

海,
我需要使用Oledb Connection从sqlserver检索数据...因为使用此方法我们可以从任何来源获取数据..
但是我的代码显示错误..我不知道为什么..


Hai,
i need to retrive the Data from sqlserver using the Oledb Connection...because using this we can get data from any source..
But my code showing error.. i don''t know why..


using System.Data;
using System.Data.OleDb;





public partial class Window1 : Window
   {
       public Window1()
       {
           InitializeComponent();
   
        }


private void button1_Click(object sender, RoutedEventArgs e)
       {
try{
             OleDbConnection oConn = new OleDbConnection(@"Provider=SQLOLEDB;Data Source=ETG75\SQLEXPRESS;Initial Catalog=SampleDb;Integrated Security=True");
        if (oConn.State != ConnectionState.Open)
               {
               oConn.Open();
               }
}
catch(Exception ex)
{

}
       }


}


该代码给出以下错误...

没有可用的错误消息,结果代码:DB_E_ERRORSOCCURRED(0x80040E21)."


将"Integrated Security = True"替换为"Trusted_connection = true"时
它给出类似用户venkat登录失败"之类的错误
但是我可以用sqlconnection连接...


请提供有关如何通过Oledb提供程序进行连接和打开的解决方案...


}


This Code giving the Following error...

"No error message available, result code: DB_E_ERRORSOCCURRED(0x80040E21)."


When replace the "Integrated Security=True " with "Trusted_connection=true "
it giving error like " Login failed for the user venkat"
But i can connect with sqlconnection...


Please provide the Solution for the How to Connect and Open through Oledb provider......

推荐答案

您保持可信连接为真,然后遵循 http://www.quackit.com/sql_server/tutorial/create_a_login.cfm [ ^ ]
you keep trusted connection true and then follow This[^] process.

This is much more clear. Look at this

http://www.quackit.com/sql_server/tutorial/create_a_login.cfm[^]


转到您的数据库在sql

您可以在其中找到安全性"链接.
因为您具有登录名".右键单击->新登录->将登录名命名为"venkat".
选择右侧的服务器角色"->选中最后一个复选框(sysadmin).

之后,选择"UserMappings"->然后检查您的数据库名称.

现在点击确定"

您的问题将得到解决
Go to your database in sql

There you find "security" link.
In that you have "Logins". Right click->new login-> give the login name as "venkat".
Select "server role" which is at right side->check the last check box(sysadmin).

After that select "UserMappings"-> then check your database name.

Now click on "ok"

Your problem will be solved


这篇关于在Ado.net中打开连接时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆