I have added a new SQL database into my project, added a table manually
in VS IDE,
and then I've run the following code that always results in an
exception?
Could it be that the connection string is wrong?
using System;
using System.Collecti ons;
using System.Collecti ons.Generic;
using System.Text;
using System.Data.Sql Client;
namespace ConsoleApplicat ion1
{
class Program
{
static void Main(string[] args)
{
string connectionStrin g =
@"Data
Source=.\SQLEXP RESS;AttachDbFi lename=F:\c#\Pr ojects\ConsoleA pplication1"
+
@"\ConsoleAppli cation1\Databas e.mdf;Integrate d
Security=True;U ser Instance=True";
SqlConnection conn = new SqlConnection(c onnectionString );
SqlCommand com = new SqlCommand("SEL ECT * FROM tabela1",
conn);
SqlDataReader reader = null;
try
{
reader = com.ExecuteRead er();
}
catch (InvalidOperati onException)
{
System.Console. WriteLine("SQL connection not
established.");
reader = null;
}
in VS IDE,
and then I've run the following code that always results in an
exception?
Could it be that the connection string is wrong?
using System;
using System.Collecti ons;
using System.Collecti ons.Generic;
using System.Text;
using System.Data.Sql Client;
namespace ConsoleApplicat ion1
{
class Program
{
static void Main(string[] args)
{
string connectionStrin g =
@"Data
Source=.\SQLEXP RESS;AttachDbFi lename=F:\c#\Pr ojects\ConsoleA pplication1"
+
@"\ConsoleAppli cation1\Databas e.mdf;Integrate d
Security=True;U ser Instance=True";
SqlConnection conn = new SqlConnection(c onnectionString );
SqlCommand com = new SqlCommand("SEL ECT * FROM tabela1",
conn);
SqlDataReader reader = null;
try
{
reader = com.ExecuteRead er();
}
catch (InvalidOperati onException)
{
System.Console. WriteLine("SQL connection not
established.");
reader = null;
}
Comment