Sql Connection Hang
Hi,
I am using .NET 2 (beta2) and are having problems with using a SqlConnection.I have created a test application that opens a sql connections, gets some basic data and then closes the connection. When i run this application as the administrator it works fine.
However if i run the application as a standard user the application hangs indefinatly on SqlConnection.Open(). I dont get any time out or any exceptions. It just hangs there.
I am using SQL Authentication. I have tested this on many computers and the same happens. My main issue is getting this to work on Windows2000 Server (Sp4).
thanks
Arran
[715 byte] By [
Arran] at [2008-1-29]
The code never makes it to
Console.WriteLine("Done");This is the test application code:
Console.WriteLine("Start...");
using (SqlConnection conn = new SqlConnection("server=MyServer;Database=MyDatabase;Uid=MyUsername;Pwd=MyPassword"))
{
SqlCommand cmd = new SqlCommand("SELECT * FROM MyTable", conn);
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
bool hasRows = dr.HasRows;
conn.Close();
}
Console.WriteLine("Done");
Console.ReadLine();
Well, firstly, you should open your conn first (before associate any command), also, try using a try/catch block to see whats going on.
There is no reason to open the connection before assigning a command to it.
its not a case of using a try/catch. This is used in a console app and if a exception was thrown (which i have already said it is not) then i would be able to solve the problem
The issue as i have said is that the process hangs for ever. No exception is ever thrown. You can leave the app running for hours and it still will not throw a exception.
Also if you run the application as Administrator it works fine.
Try setting a connection yimeout of just a couple of seconds within the connection string.
Are you trying to connect to a SQL Server on the same computer or another?
Hey mate don't know if you keep lookin' for an answer but I can tell we got the same problem; in our case we have Data access layer dll using SQLConnection.Open(); when it is referenced directly from the calling assembly it works fine no worries; when we add our simple remoting layer and make the call to the DAL through the remoting layer , the sqlconnection.open() in the DAL hangs for ever.
In our case we are using sqlserver 2005, so using sqlserver 2000 is probably not the cause of your headeach. interesting point to note is that it deos not matter if we use SSPI or SQLserver authentication to connect to the database server instance the result is the same it HANGS!!! Also we try the new named pipe channels IPC and it hangs as well on Sqlconnection .Open().
we have not solved that yet but I am thinkin tryin this:
assuming we got an windows user context permissions problem:
1) Verify the identity of the caller and the identity the remote server is running as. just to make sure the remote server is running using the calling client identity as expected by the database server SSPI authentication mechanism.
3) Try the new tcp channel secure and impersonations declarative attributes on both the client and server objects to force the calling application identity to be impersonated by the server.
if it is a code acces permission:
4) make sure that the calling assembly if fully trusted in the context of thi remoting call.
5) use security assertion in code to turn off any security check at code level for accessing resources from untrusted assembly.
if still no luck....
6) try as web service hosted in IIS and see how that works there.
anyway i found really weird after searching the net that nobody seemes to be affected by this problem. I start to think this might be .et 2.0 BETA2 bug and that's it. Hey MS let us know how how, in .net 2.o, you can remote a data access layer without sqlconnection.open() hanging for ever! as some of us ,may find this useful.
let us know if you had any luck!
cheers

, we made a serious improvement in identifying the cause of this BUG!!. We moved away from the native sqlclient classes and used oledb with the older sqloledb provider rahter than the newer and BUGGY SQLNCLI provider and the call finally worked. I will try one more thing is do the native client call in its own thread rather than withn the remoting server current thread of execution. I start to think that this migh be a thread locking issue. I'll keep you posted
trying to open the native sqlclient from its own thread did not help. so the only thing that works correctly at the moment when opening sqlserver db from a remoting server iin .net 2.0 s the older sqloledb. so we'll use that for now until MS fixes this bug in a futur release. I am keen to also play a bit with CAS as maybe this is a security feature
not completly implemented. like it would not throw yet security exception for this type of data access and therefore would never return (hangs). Though I think this is unlikely as I am able to do open files in read write from the remoting server object without muckin' around with CAS at all. anyway probably worth a try as well. BY the way we are using the new remoting security feature in .net 2 remoting. secure tcp channel, we got encryption and sspi out of the box just by modifying configu files for remoting. this is excellent !!!! I just whish sql native client would also work! MS anyone?