This simple snippet creates a connection to an SQLServer database.
using System;
using System.Data;
using System.Data.SqlClient;
class Program
{
private static SqlConnection _con = null;
static void Main(string[] args)
{
string host = ""; //Enter your host
string catalog = ""; // Enter your database name
string strProvider = "Data Source=" + host + ";Initial Catalog=" + catalog + ";Integrated Security=True";
try
{
_con = new SqlConnection(strProvider);
_con.Open();
if (_con.State == ConnectionState.Open)
{
Console.WriteLine("Connection Open");
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.ReadKey();
}
}
No comments:
Post a Comment