A
axel22
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.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string connectionString =
@"Data
Source=.\SQLEXPRESS;AttachDbFilename=F:\c#\Projects\ConsoleApplication1"
+
@"\ConsoleApplication1\Database.mdf;Integrated
Security=True;User Instance=True";
SqlConnection conn = new SqlConnection(connectionString);
SqlCommand com = new SqlCommand("SELECT * FROM tabela1",
conn);
SqlDataReader reader = null;
try
{
reader = com.ExecuteReader();
}
catch (InvalidOperationException)
{
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.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string connectionString =
@"Data
Source=.\SQLEXPRESS;AttachDbFilename=F:\c#\Projects\ConsoleApplication1"
+
@"\ConsoleApplication1\Database.mdf;Integrated
Security=True;User Instance=True";
SqlConnection conn = new SqlConnection(connectionString);
SqlCommand com = new SqlCommand("SELECT * FROM tabela1",
conn);
SqlDataReader reader = null;
try
{
reader = com.ExecuteReader();
}
catch (InvalidOperationException)
{
System.Console.WriteLine("SQL connection not
established.");
reader = null;
}