Click here to Skip to main content
15,887,485 members
Home / Discussions / C#
   

C#

 
QuestionRe: Auto Connect SQLConnection Pin
Midnight Ahri13-Sep-13 13:57
Midnight Ahri13-Sep-13 13:57 
AnswerRe: Auto Connect SQLConnection Pin
Richard MacCutchan13-Sep-13 22:05
mveRichard MacCutchan13-Sep-13 22:05 
AnswerRe: Auto Connect SQLConnection Pin
Midnight Ahri14-Sep-13 20:12
Midnight Ahri14-Sep-13 20:12 
AnswerRe: Auto Connect SQLConnection Pin
Pete O'Hanlon12-Sep-13 5:18
mvePete O'Hanlon12-Sep-13 5:18 
AnswerRe: Auto Connect SQLConnection Pin
Midnight Ahri12-Sep-13 5:36
Midnight Ahri12-Sep-13 5:36 
QuestionRe: Auto Connect SQLConnection Pin
Midnight Ahri12-Sep-13 6:45
Midnight Ahri12-Sep-13 6:45 
AnswerRe: Auto Connect SQLConnection Pin
Pete O'Hanlon12-Sep-13 8:13
mvePete O'Hanlon12-Sep-13 8:13 
QuestionRe: Auto Connect SQLConnection Pin
Midnight Ahri12-Sep-13 19:36
Midnight Ahri12-Sep-13 19:36 
Thank you very much for your instruction,
This is what I done.
C#
private void SQLClientLoader_Load(object sender, EventArgs e)
        {
            this.GetSQLState();
        }

C#
async private System.Threading.Tasks.Task<ConnectionState> GetStateAsync()
        {
            do
            {
                this.cts = new CancellationTokenSource();
                this.cnn = new SqlConnection(this.par.Constr);

                try
                {
                    await Task.Delay(2500);

                    await this.cnn.OpenAsync(cts.Token);
                }
                catch (Exception ex)
                {
                    cts.Cancel(false);

                    this.cnn.Dispose();
                    this.cts.Dispose();
                }
            } while (this.cnn.State != ConnectionState.Open);

            return this.cnn.State;
        }

C#
async private void GetSQLState()
        {
            

            if (await GetStateAsync() == ConnectionState.Open)
            {
                this.Close();
            }

            await Task.Delay(2500);
        }

It's working.
I used cancellation token, but why the OpenAsync() is not cancelled and still queue up?

Edit :
Found my solution.
Clear the connection pool, made my day guys.
Thank you helping me. Laugh | :laugh:

modified 13-Sep-13 21:43pm.

QuestionRunning SQL Server 2008 R2 without user interaction Pin
WaseemAmin11-Sep-13 21:49
WaseemAmin11-Sep-13 21:49 
AnswerRe: Running SQL Server 2008 R2 without user interaction Pin
Richard MacCutchan11-Sep-13 22:26
mveRichard MacCutchan11-Sep-13 22:26 
GeneralRe: Running SQL Server 2008 R2 without user interaction Pin
WaseemAmin12-Sep-13 5:54
WaseemAmin12-Sep-13 5:54 
AnswerRe: Running SQL Server 2008 R2 without user interaction Pin
PIEBALDconsult12-Sep-13 3:03
mvePIEBALDconsult12-Sep-13 3:03 
GeneralRe: Running SQL Server 2008 R2 without user interaction Pin
WaseemAmin12-Sep-13 6:02
WaseemAmin12-Sep-13 6:02 
GeneralRe: Running SQL Server 2008 R2 without user interaction Pin
PIEBALDconsult12-Sep-13 14:11
mvePIEBALDconsult12-Sep-13 14:11 
Generalreadonly keyword Pin
N8tiv11-Sep-13 20:38
N8tiv11-Sep-13 20:38 
GeneralRe: readonly keyword Pin
Pete O'Hanlon11-Sep-13 21:05
mvePete O'Hanlon11-Sep-13 21:05 
GeneralRe: readonly keyword Pin
N8tiv11-Sep-13 21:18
N8tiv11-Sep-13 21:18 
GeneralRe: readonly keyword Pin
Pete O'Hanlon11-Sep-13 22:58
mvePete O'Hanlon11-Sep-13 22:58 
GeneralRe: readonly keyword Pin
N8tiv11-Sep-13 23:12
N8tiv11-Sep-13 23:12 
GeneralRe: readonly keyword Pin
Abhinav S12-Sep-13 8:22
Abhinav S12-Sep-13 8:22 
GeneralRe: readonly keyword Pin
DaveyM6913-Sep-13 9:40
professionalDaveyM6913-Sep-13 9:40 
Questiondelay and back again record Pin
eng.iris11-Sep-13 18:07
eng.iris11-Sep-13 18:07 
AnswerRe: delay and back again record Pin
Eddy Vluggen12-Sep-13 2:58
professionalEddy Vluggen12-Sep-13 2:58 
GeneralRe: delay and back again record Pin
eng.iris12-Sep-13 8:21
eng.iris12-Sep-13 8:21 
GeneralRe: delay and back again record Pin
Eddy Vluggen12-Sep-13 10:42
professionalEddy Vluggen12-Sep-13 10:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.