CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2013
    Posts
    7

    SocketException When Connection to MYSQL DB From Shared Drive ... C Drive No Problem

    Hi

    I am running a very simple app that tries to connect to a MYSQL DB. When I compile and run on my local C drive, it connects with no problem. But when I compile and run the same exact code on a shared drive (f drive), I get the Socket Exception below. I've searched the NET everywhere. I've seen others with this problem but have not been able to find a solution. Any ideas why this is happening when I compile and run on my F drive but not my C drive?

    =========================Socket Exception Below ============================
    at MySql.Data.MySqlClient.NativeDriver.Open()
    at MySql.Data.MySqlClient.Driver.Open()
    at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder sett
    at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
    at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
    at MySql.Data.MySqlClient.MySqlPool.GetConnection()
    at MySql.Data.MySqlClient.MySqlConnection.Open()
    at MYSQLConnect.DB.OpenConnection()
    stem.Exception: Call to GetHostEntry failed after 00:00:00 while querying
    stname 'lxsrwebdv02.and.ma.zwickerpc.com': SocketErrorCode=NoRecovery, Err
    =11003, NativeErrorCode=11003. ---> System.Net.Sockets.SocketException: A
    coverable error occurred during a database lookup
    at System.Net.Dns.GetAddrInfo(String name)
    at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeI
    at System.Net.Dns.GetHostEntry(String hostNameOrAddress)
    at MySql.Data.Common.StreamCreator.GetDnsHostEntry(String hostname)
    --- End of inner exception stack trace ---
    at MySql.Data.Common.StreamCreator.GetDnsHostEntry(String hostname)
    at MySql.Data.Common.StreamCreator.GetStream(UInt32 timeout)
    at MySql.Data.MySqlClient.NativeDriver.Open()
    42
    able to connect to any of the specified MySQL hosts.

    ========================================================================

    Here's my program:


    class Program
    {
    MySqlConnection connection;

    public Program()
    {
    initDBConnection();
    OpenConnection();
    }


    static void Main(string[] args)
    {
    new Program();

    }
    public void initDBConnection()
    {
    string server;
    string database;
    string uid;
    string password;

    server = "SomeServer.com";
    //server = "lxsrnetservpd01.and.ma.zwickerpc.com";
    //database = "DebtorDocData";
    database = "SomeDB";
    uid = "SomeUSERID";
    password = "SomePASSWORD";
    string connectionString;
    connectionString = "SERVER=" + server + ";" + "DATABASE=" +
    database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
    connection = new MySqlConnection(connectionString);

    }
    public bool OpenConnection()
    {
    try
    {
    connection.Open();
    Console.WriteLine("CONNECTED");
    return true;
    }
    catch (MySqlException ex)
    {
    //When handling errors, you can your application's response based
    //on the error number.
    //The two most common error numbers when connecting are as follows:
    //0: Cannot connect to server.
    //1045: Invalid user name and/or password.
    switch (ex.Number)
    {
    case 0:
    Console.WriteLine("Cannot connect to server. Contact administrator");
    break;
    case 1042:
    Console.WriteLine(ex.Message);
    Console.WriteLine(ex.StackTrace);
    Console.WriteLine(ex.InnerException);
    Console.WriteLine(ex.Number);
    break;
    case 1045:
    Console.WriteLine("Invalid username/password, please try again");
    break;
    }
    Console.WriteLine(ex.Message);
    Console.ReadLine();
    return false;
    }
    }// OpenConnection

    }
    Thanks!

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: SocketException When Connection to MYSQL DB From Shared Drive ... C Drive No Prob

    Where is the connection string that connects to the C: drive versus the F: drive?

  3. #3
    Join Date
    Jul 2013
    Posts
    7

    Re: SocketException When Connection to MYSQL DB From Shared Drive ... C Drive No Prob

    Quote Originally Posted by Arjay View Post
    Where is the connection string that connects to the C: drive versus the F: drive?

    The program is not connecting to the C or F drive, it's connecting to a remote database. When the program is compiled and ran on the C drive and tries to connect to the remote DB, it has no problem connecting. But when the program is compiled and ran from a shared drive (my F drive), it has the problems detailed above.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: SocketException When Connection to MYSQL DB From Shared Drive ... C Drive No Prob

    Quote Originally Posted by Randy1969 View Post
    The program is not connecting to the C or F drive, it's connecting to a remote database. When the program is compiled and ran on the C drive and tries to connect to the remote DB, it has no problem connecting. But when the program is compiled and ran from a shared drive (my F drive), it has the problems detailed above.
    Okay. By default, .net doesn't allow running programs from a network share. From what I understand there used to be a way of doing it using Code Access Security in pre .net 4.0. In .Net 4.0 CAS has gone away.

    For more info search bing or google for "problems running a .net app from a remote drive" and "code access security".

    IMO rather than working around the built-in security features of .net, you would be better off learning how to deploy your app using a recommended method such as Click-Once deployment. Sorry to come across as sounding preachy, but it is what it is.

  5. #5
    Join Date
    Jul 2013
    Posts
    7

    Re: SocketException When Connection to MYSQL DB From Shared Drive ... C Drive No Prob

    Thank you much for the info. I am running in an ASP.NET 4.0 framework, so this would make sense.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured