I am writing a c# application. I connect to a backend SQL Server for some processing. However I hit into a weird issue today. This is my code:
static void Main(string[] args)
{
SqlConnection con = new SqlConnection("Integrated Security=true");
con.Open();
SqlCommand cmd = new SqlCommand("SELECT SERVERPROPERTY('ProductVersion')", con);
cmd.CommandType = CommandType.Text;
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
Console.WriteLine(reader.GetString(0));
Console.Read();
}
I haven’t given the server name in the Connection String, but still it connects to my local database and retrieves the required data. I am wondering how. Is the default data source set to local machine? Does “Integrated Security=true” have something to do with this?
Can someone explain this?
Thanks,
Sornakumar S
Looking at the docs on ConnectionString on MSDN you could find this information
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring(v=vs.100).aspx