Re: Connection to SQL database on local computer
- From: Otis Mukinfus <phony@xxxxxxxxxxxxxxxx>
- Date: Sat, 04 Nov 2006 06:26:11 -0600
On 4 Nov 2006 03:44:14 -0800, axel22@xxxxxxxxx wrote:
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;
}
What does the exception say? You need to tell us what the exception was that
was thrown....
Good luck with your project,
Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
.
- References:
- Connection to SQL database on local computer
- From: axel22
- Connection to SQL database on local computer
- Prev by Date: Re: memory leak or not?
- Next by Date: Re: Connection to SQL database on local computer
- Previous by thread: Connection to SQL database on local computer
- Next by thread: Re: Connection to SQL database on local computer
- Index(es):
Relevant Pages
|