Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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..


C#
using System.Data;
using System.Data.OleDb;


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

C#
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)
{

}
       }

}


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......
Posted
Updated 8-Feb-22 14:09pm

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[^]
 
Share this answer
 
v2
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
 
Share this answer
 
v2
You connection string:

Provider=SQLOLEDB;Data Source=ETG75\SQLEXPRESS;Initial Catalog=SampleDb;Integrated Security=True

Just change the below:

Provider=SQLOLEDB;Data Source=ETG75\SQLEXPRESS;Initial Catalog=SampleDb;Integrated Security=SSPI

It will work

Nagarajan AL
Singapore
+65 93255275
 
Share this answer
 
Comments
Richard Deeming 9-Feb-22 4:52am    
The Integrated Security property can be set to SSPI, True, or Yes; they all work in exactly the same way. Changing from True to SSPI will not make any difference to this already solved question.
You connection string:

Provider=SQLOLEDB;Data Source=ETG75\SQLEXPRESS;Initial Catalog=SampleDb;Integrated Security=True

Just change the below:

Provider=SQLOLEDB;Data Source=ETG75\SQLEXPRESS;Initial Catalog=SampleDb;Integrated Security=SSPI

It will work

Nagarajan AL
 
Share this answer
 
Comments
Richard Deeming 9-Feb-22 4:52am    
And why have you posted the same wrong answer twice?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900