PDA

View Full Version : A connection was successfully established with the server, but then an error occurred



m_zamani
سه شنبه 29 خرداد 1386, 10:42 صبح
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Shared Memory Provider, error: 0 - The system cannot open the file.)
سلام
کسی تا حالا با این پیغام برخورد کرده؟

reza_rad
سه شنبه 29 خرداد 1386, 10:56 صبح
آیا remote connection در sql server شما enable هست؟

m_zamani
سه شنبه 29 خرداد 1386, 10:58 صبح
آره
من connect میشم بعد از اینکه چند تا فرم باز و بسته شد این پیغام رو میده
روی فرم خاصی نیست

reza_rad
سه شنبه 29 خرداد 1386, 11:16 صبح
آره
من connect میشم بعد از اینکه چند تا فرم باز و بسته شد این پیغام رو میده
روی فرم خاصی نیست
آیا کانکشن ها به دیتابیس از داخل برنامه دستکاری میشن؟
آیا عملیات drop database یا alter database یا چنین کارهایی که باعث تغییر کانکشن ها بشه توی کد فرمها دارید؟

m_zamani
سه شنبه 29 خرداد 1386, 11:20 صبح
زیاد با database کار میکنم

reza_rad
سه شنبه 29 خرداد 1386, 11:25 صبح
I guess the problem is the connection pool. Recall that when you close
a connection from your .Net app, the connection to SQL Server is not
really closed. Instead ADO .Net lingers to it, for another 60 seconds,
and if the applicaiton opens a new connection during this time, it will
reuse the connection.

When you issue ALTER DATABASE WITH ROLLBACK IMMEDIATE, SQL Server will
terminate these connections. However, this is not something that ADO .Net
can detect. So it gives you a connection which it thinks is good, but
which isn't.

There are a couple of ways to approach this. One is to configure the
connection pool, so that all connections are dropped when you drop the
database. Another is to change the connection string, each time you
drop the database, as different connection strings gives different pools.

I would suggest that the best way, though, is simply to set up an exception
handler, so that you simply trap this error, and then try to reconnect.

For the fine details on how to implement any of the above, I would suggest
that microsoft.public.dotnet.framework.adonet is a better venue, as the
issue involved here is more one with SqlClient rather than SQL Server.


منبع:
http://www.thescripts.com/forum/thread476823.html

m_zamani
سه شنبه 29 خرداد 1386, 11:54 صبح
یعنز کانکشنم رو جایی نبستم؟
یا اینکه بستم و میخوام دوباره ازش استفاده کنم؟

reza_rad
سه شنبه 29 خرداد 1386, 12:07 عصر
نه چیزی که اینجا میگه اینه که بعضی مواقع مثل alter database ای که مثال زده اینجا، این حالت ÷یش میاد که کانکشن از طرف SQLServer بسته میشه ولی از طرف ADO.NET بسته نمیشه و یه کانکشن InValid ایجاد میشه:


When you issue ALTER DATABASE WITH ROLLBACK IMMEDIATE, SQL Server will
terminate these connections. However, this is not something that ADO .Net
can detect. So it gives you a connection which it thinks is good, but
which isn't.


اما راه حل:


There are a couple of ways to approach this. One is to configure the
connection pool, so that all connections are dropped when you drop the
database. Another is to change the connection string, each time you
drop the database, as different connection strings gives different pools.

I would suggest that the best way, though, is simply to set up an exception
handler, so that you simply trap this error, and then try to reconnect.

m_zamani
سه شنبه 29 خرداد 1386, 12:32 عصر
من متوجه راه حل نمیشم
اگه امکان داره فارسی توضیح بدید

reza_rad
سه شنبه 29 خرداد 1386, 12:52 عصر
کانکشن رو بعد از دستوراتی مثل drop database و ... ببندید. بعد کانکشن استرینگ رو تغییربدید و کانکشن جدیدی ایجاد کنید و ...

m_zamani
دوشنبه 04 تیر 1386, 09:34 صبح
من همه connection ها رو بعد از هر query میبندم و یه sql connection جدید برای command جدید ایجاد میکنم اما هنوز مشکل دارم

AminSobati
سه شنبه 05 تیر 1386, 00:07 صبح
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Shared Memory Provider, error: 0 - The system cannot open the file.)
سلام
کسی تا حالا با این پیغام برخورد کرده؟

دوست عزیزم از کدوم Edition استفاده میکنین؟ منظورم SQL Server هست