mto89
03-08-2010, 08:28
ciao, da poco mi sto interessando ai database e ADO.Net, però ho problemi nelle prime prove, sia su codice scritto da me, sia su codice esempio.
Vi incollo il pezzo:
static void Main(string[] args)
{
SqlConnectionStringBuilder bd = new SqlConnectionStringBuilder();
bd.DataSource = "localhost";
bd.InitialCatalog = "Northwind";
bd.IntegratedSecurity = true;
SqlConnection conn = new SqlConnection(bd.ConnectionString);
try
{
conn.Open();
SqlCommand com = new SqlCommand("SELECT * FROM Products");
SqlDataReader reader = com.ExecuteReader();
........
Quando l'esecuzione arriva al codice in rosso, si apre la shell e non accade nient'altro, devo chiuderla.
Nel blocco catch non ci entra...qual'è la causa secondo voi?
Grazie.
EDIT: mi correggo, dopo una decina di secondi entra nel catch dandomi il seguente messaggio di errore:
“A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. <Provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server>
Il database in questione è nella cartella del progetto
Vi incollo il pezzo:
static void Main(string[] args)
{
SqlConnectionStringBuilder bd = new SqlConnectionStringBuilder();
bd.DataSource = "localhost";
bd.InitialCatalog = "Northwind";
bd.IntegratedSecurity = true;
SqlConnection conn = new SqlConnection(bd.ConnectionString);
try
{
conn.Open();
SqlCommand com = new SqlCommand("SELECT * FROM Products");
SqlDataReader reader = com.ExecuteReader();
........
Quando l'esecuzione arriva al codice in rosso, si apre la shell e non accade nient'altro, devo chiuderla.
Nel blocco catch non ci entra...qual'è la causa secondo voi?
Grazie.
EDIT: mi correggo, dopo una decina di secondi entra nel catch dandomi il seguente messaggio di errore:
“A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. <Provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server>
Il database in questione è nella cartella del progetto