G
Guest
I am a newbie to both .Net and Sql Server and I am trying to access the
database by using the ADO.Net data reader. This is actually one of the
execises in a book that I am reading. However, when I run this program, there
is an error saying that "Login failed for user 'sa'. Reason: Not associated
with a trusted SQL Server connection." Are there some settings I have to
change in the Sql Server? Please help me!
//--------------------------------------------------------------
using System;
using System.Data;
using System.Data.SqlClient;
class MyApp
{
static void Main()
{
try{
SqlConnection conn = new
SqlConnection("server=localhost;uid=sa;pwd=;database=pubs");
conn.Open();
SqlCommand comm = new SqlCommand("select * from titles", conn);
SqlDataReader reader = comm.ExecuteReader();
while(reader.Read())
Console.WriteLine(reader.GetString(1));
conn.Close();
}
catch(Exception e){
Console.WriteLine(e.Message);
}
}
}
//--------------------------------------------------------------
database by using the ADO.Net data reader. This is actually one of the
execises in a book that I am reading. However, when I run this program, there
is an error saying that "Login failed for user 'sa'. Reason: Not associated
with a trusted SQL Server connection." Are there some settings I have to
change in the Sql Server? Please help me!
//--------------------------------------------------------------
using System;
using System.Data;
using System.Data.SqlClient;
class MyApp
{
static void Main()
{
try{
SqlConnection conn = new
SqlConnection("server=localhost;uid=sa;pwd=;database=pubs");
conn.Open();
SqlCommand comm = new SqlCommand("select * from titles", conn);
SqlDataReader reader = comm.ExecuteReader();
while(reader.Read())
Console.WriteLine(reader.GetString(1));
conn.Close();
}
catch(Exception e){
Console.WriteLine(e.Message);
}
}
}
//--------------------------------------------------------------