[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1748
  • Last Modified:

Unhandled Exception: System.Data.SqlClient.SqlException: Login failed for user '

Unhandled Exception: System.Data.SqlClient.SqlException: Login failed for user '
(null)'. Reason: Not associated with a trusted SQL Server connection.

I am running the c# code (COMMANDLINE) from a remote computer and giving the above error.If I running the
 code onthe local machine where the sql database is ,then it runninG fine.

I have tried
1.Impersonation code on the various sites
2.Added the aspnet  user to the database with the rights
BUT STILL IT IS NOT LOGGING IN .

 

SqlConnection con=new SqlConnection("data source=10.100.0.79; uid=****; password=***; database=test1;Trusted_Connection=yes;connection timeout=30");

             con.Open();
             SqlCommand command2=new SqlCommand("select userid from _user   ",con);
             SqlDataReader Records=null;  //data reader
             Records=command2.ExecuteReader();



0
sacchit
Asked:
sacchit
1 Solution
 
sacchitAuthor Commented:
Hi,
    IT is very urgent
0
 
Carl TawnSystems and Integration DeveloperCommented:
Take "Trusted_Connection=yes;" out of the connection string and then try it.  Trusted connection implies windows authentication rather than the UID and Password that you are passing in.

Hope this helps.
0
 
Razzie_Commented:
Hey sacchit,

From the SQL Enterprise Manager right click your server to get the
properties.

Select the security tab and switch authentication to "Sql Server and
Windows", restart the service or better yet restart the whole server.

Solution from: http://www.dotnet247.com/247reference/msgs/26/131323.aspx

Might try if this works!

HTH,

Razzie
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rajaloysiousCommented:
i agree with a carl_tawn...

cheers
0
 
Mohammed NasmanSoftware DeveloperCommented:
try write it as

SqlConnection con=new SqlConnection("data source=10.100.0.79; initial catalog=test1;integrated security = SSPI");
0
 
sacchitAuthor Commented:
The server is already in 'Sql Server and Windows' mode  

I tried  mnasmans con string
Still the same error.

Unhandled Exception: System.Data.SqlClient.SqlException: Login failed for user '
(null)'. Reason: Not associated with a trusted SQL Server connection.
   at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransactio
n)
0
 
Mohammed NasmanSoftware DeveloperCommented:
are you using domain in your network?

if so try to add
<identity impersonate="true" />
to your web.config file
0
 
sacchitAuthor Commented:
We we are using domain.The applicatin is a command line exe .So how to impersonate

I tried to impersonate using various  impersonation code on  in c#  but it dint happen ,Can anybody give me a good working example of impersonated login on remote machine  or Is there some other problem.
.
0
 
melodiesoflifeCommented:
Hi sacchit

To connect over IP address, the connection string must be:

"Data Source=10.100.0.79,1433;Network Library=DBMSSOCN;Initial Catalog=test1;User ID=sa;Password=xxx;"
0
 
dunglaCommented:
Connect via an IP address:
"Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=pubs;User ID=sa;Password=asdasd;"

    (DBMSSOCN=TCP/IP instead of Named Pipes, at the end of the Data Source is the port to use (1433 is the default))

from http://www.connectionstrings.com/
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now