Merhaba,
Forumda ilk mesajım belkide son
Çorbada bizimde tuzumuz olsun 
Örnek Config Dosyası
Forumda ilk mesajım belkide son
Kod:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
namespace FMobile.Helpers
{
public class SqlHelper
{
protected static readonly string constr = ConfigurationManager.ConnectionStrings["FConnection"].ConnectionString;
public static string DBName()
{
SqlConnection con = new SqlConnection(constr);
return con.Database;
}
public static int ExceuteNonQuery(string sqlstr, CommandType type, SqlParameter[] parameters, string conString)
{
SqlConnection con = new SqlConnection(constr);
if (conString != null)
con.ConnectionString = conString;
SqlCommand cmd = new SqlCommand(sqlstr, con);
cmd.CommandType = type;
if (parameters != null)
cmd.Parameters.AddRange(parameters);
int numrows = 0;
try
{
con.Open();
numrows = cmd.ExecuteNonQuery();
}
catch (SqlException ex)
{
throw ex;
}
finally
{
if (con.State != ConnectionState.Closed)
con.Close();
}
return numrows;
}
public static object ExecuteScalar(string sqlstr, CommandType type, SqlParameter[] parameters, string conString)
{
SqlConnection con = new SqlConnection(constr);
if (conString != null)
con.ConnectionString = conString;
SqlCommand cmd = new SqlCommand(sqlstr, con);
cmd.CommandType = type;
if (parameters != null)
cmd.Parameters.AddRange(parameters);
object result = null;
try
{
con.Open();
result = cmd.ExecuteScalar();
}
catch (SqlException ex)
{
throw ex;
}
finally
{
if (con.State != ConnectionState.Closed)
con.Close();
}
return result;
}
public static SqlDataReader ExecuteReader(string sqlstr, CommandType type, SqlParameter[] parameters, string conString)
{
SqlConnection con = new SqlConnection(constr);
if (conString != null)
con.ConnectionString = conString;
SqlCommand cmd = new SqlCommand(sqlstr, con) { CommandType = type };
/*SqlConnection.ClearPool(con);*/
if (parameters != null)
cmd.Parameters.AddRange(parameters);
SqlDataReader reader;
try
{
con.Open();
reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (SqlException ex)
{
if (con.State != ConnectionState.Closed)
con.Close();
throw ex;
}
return reader;
}
}
}
Kod:
<connectionStrings>
<add name="FConnection" connectionString="Data Source=SUNUCUADRESI;Initial Catalog=VERITABANI;User ID=KULLANICI;Password=SIFRE;Connection Timeout=300;" providerName="System.Data.SqlClient"/>
</connectionStrings>
Son düzenleme: