简体   繁体   中英

Asp.Net - SqlConnection failed from dll

I've already seen some similar question but none of them has received a valid solution.

I've an asp.net web site which reference a dll with some method in order to execute a simple operation on database (CRUD operations). When I need to do some "select * from" I call a method of dll passing it the connection string, but any operation fails with error message like this: System.Data.SqlClient.SqlException: Login failed for user 'DOMAIN\\MACHINENAME$'.

It's imposibile whereas my connection is right (user id=sa; password=password) and it is the same connection stirng that I use for all my web site. Idon't use integrated security=true, I'm just using sa account with password.

THE ONLY different between all my web site and this project is just that CRUD operation come from different assembly (my dll).

The code is very simple:

// Asp.Net Button Click
MyDll.MyClass DbClass = new MyDll.MyClass();
DbClass.ConnectionString = "Data Source=Source;Integrated Security=false;initial Catalog=NorthWind;user id=sa;password=password;Persist Security Info=true";
DbClass.ExecuteQuery(select * from tableName);
// ExecuteQuery method do other stuff as SqlDataAdapter sda = new....sda.Fill(myDataset)..

..Any ideas?

The error message states that you are trying to use Integrated Security and is using your domain account to make a connection with sql server

But your connection string is correct and it might be possible that the dll have its connectionstring that overwrites your given connectionstring

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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