By convention, things like program options and credentials are often stored in a configuration file. Since this is a separate file from the executable file for a program, it permits one to change these parameters in the configuration file using any text editor such as notepad without having to make changes to the program itself.In the case of Windows programs built with Visual Studio the configuration file is generally named app.config.

In the case of Twitter to SQL we store two sets of credentials in the app.config file, namely:

  • The database connection string – this has the information, including the user ID and password, to permit the program to connect t SQL Server.
  • Twitter API keys – these four keys contain the user specific keys assigned by Twitter to the user. These are used to validate the application and user with Twitter at run time to permit access.

Here is a sample app.config file with the sensitive data replaced by Xs:


<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
  <connectionStrings>
    <add name="SqlServerTarget" connectionString="xxxxxxxxxxxx" />
  </connectionStrings>
  <appSettings>
    <!-- Fill in your consumer key and secret here to make the OAuth sample work. -->
    <!-- Twitter sign-up: https://dev.twitter.com/ -->
    <!-- FSharp Follower -->
    <add key="APIkey" value="xxxxxxxxxxxx" />
    <add key="APIsecret" value="xxxxxxxxxxxx" />
    <add key="accessToken" value="xxxxxxxxxxxx" />
    <add key="accessTokenSecret" value="xxxxxxxxxxxx" />
  </appSettings>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.18.0" newVersion="4.2.18.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime
</configuration>


For information on how to construct a connection string for the SQL Server database see the Microsoft documentation for SQL Server. Alternatively this website https://www.connectionstrings.com/sql-server/ provides excellent guidance and samples.

As for the four keys required by Twitter the reader is referred to the Twitter API documentation at https://dev.twitter.com/ which provides documentation on the Twitter API, guidance on accessing the API as well as details on how to register for and obtain keys. Since the actual Twitter access is done by the programs contained in the LINQ to Twitter project, https://linqtotwitter.codeplex.com/, the user is referred to the documentation there for additional guidance.

If you experience problems accessing Twitter with this project the user should attempt to access Twitter using the sample application contained at LINQ to Twitter, https://linqtotwitter.codeplex.com/. If that works them you know that your API keys are good. If on the other hand that does not work for you it is recommended that you debug using that sample application before returning to this project as that sample is simpler and involves fewer components.

Last edited Mar 6, 2014 at 3:59 AM by JonnyBoats, version 1