Salve,
ho un script .aspx con il quale effettuo l'upload di un'immagine, il suo resize e la creazione della miniatura.
Vorrei effettuare il salvataggio all'interno del database di tipo Sql, ma ho dei problemi.
Per prima cosa ho aggiunto in cima alla pagina:
<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "System.Data.SqlClient" %>
Successivamente dopo il salvataggio dell'immagine apro la connessione:
Codice PHP:
string nomedelfile = Path.GetFileName(uploadedFiles[0].FileName);
SqlConnection connection = new SqlConnection();
connection.ConnectionString = "Data Source=ip_Server; Initial Catalog=Nome_Database; User Id=nome_utente; Password=password";
connection.Open();
Dopo di che effettuo la insert:
Codice PHP:
string SQL = "INSERT INTO prova (picture1) VALUES ('" + nomedelfile + "')";
SqlCommand comando = new SqlCommand(SQL, connection);
comando.CommandText = SQL;
try
{
comando.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
finally
{
connection.Close();
}
L'upload lo effettua correttamente ma per l'inserimento nel db, mi restituisce quest'errore:
Codice PHP:
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Come posso risolvere??
Grazie, Kuilsera