Home > Net >  An error SQL database connection, please?
An error SQL database connection, please?

Time:01-27

Two connection string (corresponding to the Windows authentication and essentially authentication) is correct, the SCN. The Open (); This sentence errors,
Exception information for "Internal connection fatal error." what went wrong, should be how to modify? If the connection string to write it?
 
Using Microsoft. The Data. SqlClient.
using System;

The namespace SqlDatabase
{
Class Program
{
The static void Main (string [] args)
{
Console. WriteLine (" Hello World!" );
String SqlCon="integrated security=SSPI; Data source='(local);='StarsData' initial catalog ";
//SqlCon="uid='sa'. The PWD='111'. Data source='(local);='StarsData' initial catalog ";
SqlConnection SCN=new SqlConnection ();
Try
{
SCN. The ConnectionString=SqlCon;
SCN. The Open ();
SqlCommand SCD=new SqlCommand ();
SCD. Connection=SCN;
Scd.Com mandText="select ObjectName from dbo. DeepSkyObject where Type='N'";
SqlDataReader SDR=SCD. ExecuteReader ();
While (SDR) Read ())
{
Console. WriteLine (" celestial: "+ SDR. Get string (0));
}
}
The catch (Exception e)
{
Console. WriteLine (e.M essage);
}
The finally
{
If (SCN.=null)
{
SCN. The Close ();
}
}
}
}
}
  •  Tags:  
  • C#
  • Related