title: Troubleshooting a Connection String in IIS 7 - how to test what's going wrong
body: <p>I have a complex problem and I am not sure what is causing it.  The short of it is, I pretty much have access to test anything I need to, but I am not sure the best way to troubleshoot a database connection string issue in my scenario.</p>
  
  <p>My development environment is quite a bit different than my test environment.  My test environment is in a DMZ.  My development environment is within the same domain as the database server.</p>
  
  <p>In my development environment, I am running on my desktop and connecting with a connection string and using a trusted connection.  </p>
  
  <p>Int the DMZ I have deployed my files on a system drive that IIS 7 points to on the same server.  Because the test environment is on the DMZ, I am using an ip address of the server and a special port number that I must specify in my connection string.</p>
  
  <p>My web application does not house connection string.  I keep connection string in a .cs file and based on Evironment.machineName variable in .Net, the application decides at runtime which connection string to use and stores that into a global static varibale  so I basically have:</p>
  
  <pre><code>public static readonly string strDBConnDev = "connection stuff here";
  public static readonly String strDBConnTest = "connection stuff here";
  
  public static String strDBConn;
  </code></pre>
  
  <p>Then I have a function that fires on a pageload that runs</p>
  
  <pre><code>public static void setEnvVars()
  {
  
  // This is psuedocode
  
  if(environment.machinename = "mydevmachine")
  
  {       
  strDBConn = strDBConnDev;
          }
  
          if(environment.machinename = "mytestmachine")
          {
              strDBConn = strDBConnTest;
          }
  }
  </code></pre>
  
  <p>I make a connection on dev that is successful.  The connection string, or something about it is not right.  I am using the .Net Data Provider, using 
  System.Data.SqlClient.  It is important that I continue to use this. I have not configured any connection string in the IIS 7 database section as that has not seemed to be necessary in our other environments.  </p>
  
  <p>According to an article I found: There are 2 formats.  The one that my dev machine uses</p>
  
  <p>// .NET DataProvider -- Trusted Connection</p>
  
  <p>using System.Data.SqlClient;</p>
  
  <pre><code>SqlConnection conn = new SqlConnection();
  conn.ConnectionString =
  "Data Source=ServerName;" +
  "Initial Catalog=DataBaseName;" +
  "Integrated Security=SSPI;";
  conn.Open();
  </code></pre>
  
  <p>and the connection via ip that i need my test in the dmz to use:</p>
  
  <p>// .NET DataProvider -- via IP Address</p>
  
  <pre><code>using System.Data.SqlClient;
  
  SqlConnection conn = new SqlConnection();
  conn.ConnectionString =
  "Network Library=DBMSSOCN;" +
  "Data Source=xxx.xxx.xxx.xxx,[port number];" +
  "Initial Catalog=DataBaseName;" +
  "User Id=UserName;" +
  "Password=Secret;";
  conn.Open();
  </code></pre>
  
  <p>My conundrum is that I have troubleshot to the point that I know that that connection string variable is being set when in the DMZ.  However my connection fails and yet I do not get an error.  It just fails quietly.  I checked IIS logs on the DMZ and found no evidence of a clue or hint.  I also checked the windows Application logs and did not find anything there, which I thought was pretty surprising.  </p>
  
  <p>I feel stuck at this point because I feel like I need troubleshooting ideas so that I can understand and test the connection and visibility and credentials of the database server from my dmz host.  </p>
  
  <p>A little background in how I am deploying is that I am building on my machine, then copying the files to my c# web application to the folder on the dmz host. The code runs nice until it tries to make a call to the db.</p>
  
  <p>I feel like I need some help with my "skills", basically knowing when / how to troubleshoot and also what to ask of my network peeps.</p>