Facing error : Format of the initialization string does not conform to specification starting at index 0!

Hamed Vaziri 136 Reputation points
2023-03-17T22:36:45.1566667+00:00

Hi

in my windows form application, (for some reasons) i've encrypt my connectionString in configuration file & decrypt it then place to an static variable. It works correctly.

Now to change all tableAdapters in my app to set it's connectionString to my static variable, i've written this code which use reflection to access connection information of the given tableAdapter(s) :

public static void InitAdapters(Component[] arrComponents)
        {
            foreach (Component cmp in arrComponents)
            {
                PropertyInfo pConnection = cmp.GetType().GetProperty("Connection", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
                object objConnection = pConnection.GetValue(cmp, null);
                PropertyInfo pConnectionString = objConnection.GetType().GetProperty("ConnectionString");
                pConnectionString.SetValue(objConnection, Singleton.StaticConnectionString, null);
            }
        }

my problem is that, i'm facing this error :

Format of the initialization string does not conform to specification starting at index 0

at line :

object objConnection = pConnection.GetValue(cmp, null);

The interesting part is at debug mode, when arrives to the given line, i've add to quick watch & re evaluate then it works!!!!!!

What's the problem & how to solve it?

Thanks in advance

Developer technologies Windows Forms
Developer technologies C#
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2023-03-20T08:21:34.5633333+00:00

    Hi @Hamed Vaziri ,

    This problem is usually caused by the connection string containing extra single quotes and double quotes.

    Please check the connection string in the static variable.

    Best Regards. 

    Jiachen Li 

    ---------- 

    If the answer is helpful, please click "Accept Answer" and upvote it. 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.   

    5 people found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.