Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
i have text file having connection string info. I want to change connection string in app.config using the content of textfile. in VB.net please! thanks!

VB
<connectionStrings>
        <add name="Inventory_System.My.MySettings.AWDConnectionString"
            connectionString="Data Source=instance name;Initial Catalog=db name;User Id=username; Password=password"
            providerName="System.Data.SqlClient" />
    </connectionStrings>
Posted
Updated 14-Nov-13 3:32am
v2
Comments
Sergey Alexandrovich Kryukov 14-Nov-13 12:52pm    
Suppose you change it in this file, than what? This is not how app.config works.
—SA

1 solution

This is not how "app.config" works. There is no "app.config" file during runtime, it is not a part of the product. The file you can deploy is the same file renamed as "youApplicationName.exe.config". And this file content is assumed to be immutable after the application is started. Even if change the file content itself, it won't modify the behavior of your application. If you need to reconnect or get another connection with different connection string, you need to use some other mechanism for this purpose. For example, you could have a choice in a fixed set connection strings, or something; it depends on your architecture.

—SA
 
Share this answer
 
Comments
jerahmeel salayog 14-Nov-13 19:16pm    
thanks for the info..
Sergey Alexandrovich Kryukov 14-Nov-13 20:23pm    
Sure. Are you going to accept the answer formally, or you need more help? If you need more help, information on your goals is needed...
—SA
jerahmeel salayog 14-Nov-13 20:31pm    
I have problem running the solution when the connection string from the app.config is not changed. "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"
Sergey Alexandrovich Kryukov 14-Nov-13 20:41pm    
Do you even need to have more then one connection string? This tells you thank you don't, you just need only one, by correct. I have no idea how could it bring you to the idea of changing it.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900