using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;


public partial class StoredProcedures
{
  [Microsoft.SqlServer.Server.SqlProcedure]
  public static void InsertRowOfTestData2()
  {
    string connStr;
    if (SqlContext.IsAvailable)
      connStr = "context connection=true";
    else
      connStr = GetConnectionStringFromConfigFile();
    // the rest of the code is identical
    using (SqlConnection conn = new SqlConnection(connStr))
    using (SqlCommand cmd = 
      new SqlCommand("insert into test values ('testdata')", conn))
    {
      conn.Open();
      // The value of i is the number of rows affected
      int i = cmd.ExecuteNonQuery();
    }
  }

  static string GetConnectionStringFromConfigFile()
  {
    // for now, just return the string
    return "server=.;integrated security=sspi;database=test";
  }
};
