Click here to Skip to main content
16,022,060 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
when I passing connection string to Connection constructor it giving above exception in windows form application

{"Format of the initialization string does not conform to specification starting at index 0."}


What I have tried:

Connection string in app.config is as follows
<add name="DBConnectionString" connectionString="Data Source=SONALI\HPPAVSQLEXPRESS;Initial Catalog=testdb;Persist Security Info=True;User ID=sa;Passwordadmin123" providerName="System.Data.SqlClient" />


then I am reading Connection string and stored in string Variable
as
public Form1()
       {
           InitializeComponent();
       }

       string connectionstring = ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString;


then passing this string variable to connection class constructor as
SqlConnection connection = new SqlConnection(connectionstring);


but here it is giving above mentioned exception
Posted
Updated 19-Feb-18 23:31pm

A connection string to a MS SQL instance begins with Server=, not Data Source=.
You should have a look at The Connection Strings Reference[^]
 
Share this answer
 
<add name="DBConnectionString" connectionString="Data Source=SONALI\HPPAVSQLEXPRESS;Initial Catalog=testdb;Persist Security Info=True;User ID=sa;Passwordadmin123" providerName="System.Data.SqlClient" />


try

<add name="DBConnectionString" connectionString="Data Source=SONALI\HPPAVSQLEXPRESS;Initial Catalog=testdb;Persist Security Info=True;User ID=sa;Password=admin123" providerName="System.Data.SqlClient" />
 
Share this answer
 

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