title: SQL connection string in web service c#
body: <p>Hi I'm having a problem finding the correct connection statement for my web-service to an sql-server database. I'm trying to retrieve data from my database to check a users login details.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Data;
  using System.Data.SqlClient;
  
  namespace BTC_Service
  {
      public class UseDatabase
      {
          SqlConnection sqlConn;
  
          internal Boolean Connect()
          {
              try
              {
                  sqlConn = new SqlConnection(@"Integrated Security=true; Initial Catalog=BTCFS_DataBase; Data Source=.\SQLEXPRESS;");
                  sqlConn.Open();
                  return true;
              }
              catch (SqlException ex)
              {
                  return false;
              }
          }
  
          internal void DisconnectDatabase()
          {
              sqlConn.Close();
          }
  
          internal Boolean ExecuteCommand(String query)
          {
              try
              {
                  SqlCommand cmd = sqlConn.CreateCommand();
                  cmd.CommandText = query;
                  cmd.ExecuteNonQuery();
                  return true;
              }
              catch (SqlException ex)
              {
                  return false;
              }
          }
  
          internal SqlDataReader ExecuteQuery(String query)
          {
              try
              {
                  SqlCommand cmd = sqlConn.CreateCommand();
                  cmd.CommandText = query;
                  return cmd.ExecuteReader();
              }
              catch (SqlException ex)
              {
                  return null;
              }
           }
      }
  }
  </code></pre>
  
  <p>The database is created with sql-server 2008 and the path for it is:</p>
  
  <p>C:\BTCFS_DataBase\db_BTDC_data.mdf</p>
  
  <p>and the log file</p>
  
  <p>C:\BTCFS_DataBase\db_BTDC_log.ldf</p>
  
  <p>There is no password for the database and the code is as follows:</p>
  
  <pre><code>USE master
  GO
  
  create database db_BTCFC 
  ON PRIMARY
  (
      NAME =  'db_BTCFC_Data',
      FILENAME = 'c:\BTCFS_DataBase\db_BTDC_data.mdf',
      SIZE = 5MB,
      FILEGROWTH = 10%    
  )
  LOG ON
  (
      NAME = 'db_BTFC_log',
      FILENAME = 'c:\BTCFS_DataBase\db_BTDC_log.ldf',
      SIZE = 5MB,
      FILEGROWTH = 10%
  )
  GO
  </code></pre>
  
  <p>Is there any suggestion to what I am doing wrong?
  Should I add the database to visual studio in a specific way?
  Or am i creating my database in the wrong way?</p>
  
  <p>Thank you in advance.</p>