3 Replies - 303 Views - Last Post: 14 July 2012 - 06:50 AM Rate Topic: -----

#1 nighttrain  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 228
  • Joined: 22-September 10

Connection String

Posted 14 July 2012 - 02:30 AM

For always i was using for this connection string:
SqlConnectionStringBuilder connectionString = new SqlConnectionStringBuilder();
                        connectionString.DataSource = @"(local)";
                       connectionString.IntegratedSecurity = false;
                       connectionString.InitialCatalog = "myDB";
                       connectionString.UserID = "john";
                        connectionString.Password = "mypassword";
                        connectionString.Encrypt = true;
                        connectionString.ConnectTimeout = 2;
                        connectionString.TrustServerCertificate = true;



But i want now to put this connection string into a app.conf.
I have seen that statment:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
    </configSections>
    <connectionStrings>
      <add name="connectionString" connectionString="Data Source=(local);Initial Catalog=myDB;User ID=john;Password=mypassword"
          providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>



My question is how should i put my my connection string correctly in above xlm. Could someone show me on my example?

Is This A Good Question/Topic? 0
  • +

Replies To: Connection String

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 1925
  • View blog
  • Posts: 5,736
  • Joined: 05-May 12

Re: Connection String

Posted 14 July 2012 - 02:37 AM

At some point in your code, you do something like connectionString.ConnectionString, right? Copy and paste the contents of this into the config file.
Was This Post Helpful? 0
  • +
  • -

#3 nighttrain  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 228
  • Joined: 22-September 10

Re: Connection String

Posted 14 July 2012 - 02:47 AM

I got whole code ready to use only just need to know how to past this contest:

SqlConnectionStringBuilder connectionString = new SqlConnectionStringBuilder();
                        connectionString.DataSource = @"(local)";
                       connectionString.IntegratedSecurity = false;
                       connectionString.InitialCatalog = "myDB";
                       connectionString.UserID = "john";
                        connectionString.Password = "mypassword";
                        connectionString.Encrypt = true;
                        connectionString.ConnectTimeout = 2;
                        connectionString.TrustServerCertificate = true;



in app.conf, could you please show me how to do this?

For example it will be correct?:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
    </configSections>
    <connectionStrings>
      <add name="connectionString" connectionString="Data Source=@(local);Initial Catalog=myDB;IntegratedSecurity=false;Encrypt=true;ConnectTimeout=2;TrustServerCertificate=true;User ID=john;Password=MyPassword"
          providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>


This post has been edited by nighttrain: 14 July 2012 - 02:50 AM

Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 1925
  • View blog
  • Posts: 5,736
  • Joined: 05-May 12

Re: Connection String

Posted 14 July 2012 - 06:50 AM

No. Where did the '@' come from?

Let me try again. Why guess? Add a line 10: Console.WriteLine(connectionString.TrustServerCertificate); or a MessageBox(); or as I had initially suggested, step through with the debugger. Get the real value and paste that in.

This post has been edited by Skydiver: 14 July 2012 - 06:52 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1