Click here to Skip to main content
15,900,461 members
Home / Discussions / C#
   

C#

 
QuestionSyncoronizing voice and text Pin
Nafiseh Salmani18-Aug-06 20:08
Nafiseh Salmani18-Aug-06 20:08 
AnswerRe: Syncoronizing voice and text Pin
Mircea Grelus19-Aug-06 3:55
Mircea Grelus19-Aug-06 3:55 
QuestionRe: Syncoronizing voice and text Pin
Nafiseh Salmani19-Aug-06 20:13
Nafiseh Salmani19-Aug-06 20:13 
AnswerRe: Syncoronizing voice and text Pin
Dave Kreskowiak19-Aug-06 20:33
mveDave Kreskowiak19-Aug-06 20:33 
QuestionHow to add all files in a directory structure to a project ? Pin
hongheo7618-Aug-06 18:56
hongheo7618-Aug-06 18:56 
AnswerRe: How to add all files in a directory structure to a project ? Pin
Stefan Troschuetz18-Aug-06 21:55
Stefan Troschuetz18-Aug-06 21:55 
AnswerRe: How to add all files in a directory structure to a project ? Pin
Ed.Poore19-Aug-06 6:08
Ed.Poore19-Aug-06 6:08 
QuestionCan't get SqlConnection() to connect after first failure Pin
shultas18-Aug-06 16:43
shultas18-Aug-06 16:43 
Hi All,

I have a SQL Server at my office. I can VPN into the office from home in order to access the server. I have a program that makes a connection to this server when it loads up. I do this in a thread, but for the sake of this message I actually put this code in the _Load portion of my app (just to take the delegates, etc, out of the equation). I have a worker thread that checks the connection as well and updates a label to tell you if you are connected or not. If the worker thread detects it is not connected, it will try to re-connect. If I VPN into the office, and then run the app, it works fine. If I disconnect (after I've run the program and connected for the first time) the app does what it should and tells me that I'm disconnected. If I then VPN back in, after a few seconds the label is updated and it says the connection is restored.

The problem that I am facing is that if I am not VPN'd into my office (ie, it cannot see the server from the beginning) it will NEVER connect. It just keeps erroring out in the catch block and the message is that the connection could not be established. I have tried switching the Data Source over to an IP address just to be sure that it was not the DNS resolving that was messing up, and that does not work either. I have tried putting a Thread.Sleep(5000) in the Catch block upon failure just in case I was bombarding the server with too much, that does not work either. I cannot figure out what the problem is. I've done a bunch of different tries at it (ie, redo the connection string each try on the while loop and call Dispose()) ... nothing works. If anyone knows what my problem is I would appreciate a helping hand.

Here's what the code looks like in a nutshell.


while (!bConnectedToServer)
{
myConnectionString = "Initial Catalog=PROGARCHIVE;Data Source=192.1.1.20;User ID=test;Password=test;Connection Timeout=5;";
myConnection = new SqlConnection(myConnectionString);
try
{
myConnection.Open();
bConnectedToServer = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
myConnection.Dispose();
Thread.Sleep(5000); //I've tried it with various values and none at all
}
}

I have also tried something of the nature:

myConnectionString = "Initial Catalog=PROGARCHIVE;Data Source=192.1.1.20;User ID=test;Password=test;Connection Timeout=5;";
myConnection = new SqlConnection(myConnectionString);
while (!bConnectedToServer)
{
try
{
myConnection.Open();
bConnectedToServer = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
Thread.Sleep(5000); //I've tried it with various values and none at all
}
}


AnswerRe: Can't get SqlConnection() to connect after first failure [modified] Pin
coolestCoder18-Aug-06 19:53
coolestCoder18-Aug-06 19:53 
GeneralRe: Can't get SqlConnection() to connect after first failure Pin
Colin Angus Mackay18-Aug-06 23:14
Colin Angus Mackay18-Aug-06 23:14 
AnswerRe: Can't get SqlConnection() to connect after first failure Pin
Colin Angus Mackay18-Aug-06 23:16
Colin Angus Mackay18-Aug-06 23:16 
GeneralRe: Can't get SqlConnection() to connect after first failure Pin
shultas19-Aug-06 5:00
shultas19-Aug-06 5:00 
QuestionCustom Controls Pin
Tyrus18218-Aug-06 15:51
Tyrus18218-Aug-06 15:51 
AnswerRe: Custom Controls Pin
Martin#19-Aug-06 8:49
Martin#19-Aug-06 8:49 
GeneralRe: Custom Controls Pin
Tyrus18219-Aug-06 14:05
Tyrus18219-Aug-06 14:05 
GeneralRe: Custom Controls Pin
Martin#20-Aug-06 9:38
Martin#20-Aug-06 9:38 
Questiona question about Report. Pin
Mrguoxiang18-Aug-06 12:03
Mrguoxiang18-Aug-06 12:03 
QuestionError running Windows service in release mode Pin
Bharat Gadhia18-Aug-06 11:03
Bharat Gadhia18-Aug-06 11:03 
AnswerRe: Error running Windows service in release mode Pin
coolestCoder18-Aug-06 20:00
coolestCoder18-Aug-06 20:00 
GeneralRe: Error running Windows service in release mode Pin
Bharat Gadhia21-Aug-06 6:01
Bharat Gadhia21-Aug-06 6:01 
QuestionProblem with control docking Pin
AngryC18-Aug-06 10:49
AngryC18-Aug-06 10:49 
QuestionPDF Creation in C# Pin
Aaron Schaefer18-Aug-06 10:16
Aaron Schaefer18-Aug-06 10:16 
AnswerRe: PDF Creation in C# Pin
stancrm18-Aug-06 10:39
stancrm18-Aug-06 10:39 
AnswerRe: PDF Creation in C# Pin
Suelinda_W7-Sep-06 10:19
Suelinda_W7-Sep-06 10:19 
Questionwhat would the best way to approach this project be? Pin
mmatteson18-Aug-06 9:43
mmatteson18-Aug-06 9:43 

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.