Sto imparando a programmare in asp.net ma non riesco a connettermi al database sql server 2014
Il codice � il seguente
Con questo codice ho l'errore che l'accesso non � riuscito per l'utente Michele nonostante nome utente e password sono corretti.codice:using (SqlConnection connection = new SqlConnection("Server=DESKTOP-R4FN8DD\\SQLEXPRESS;Database=pubs;User Id=Michele;Password=*****;")) using (SqlCommand cmd = new SqlCommand("SELECT au_id AS ID, au_lname As Nome FROM [dbo].[authors]", connection)) { try { connection.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { // Check is the reader has any rows at all before starting to read. if (reader.HasRows) { // Read advances to the next row. while (reader.Read()) { // To avoid unexpected bugs access columns by name. int ID = reader.GetInt32(reader.GetOrdinal("ID")); String Nome = reader.GetString(reader.GetOrdinal("Nome")); form1.InnerText += "ID: " + ID; form1.InnerText += "Nome: " + Nome; form1.InnerText += "<br />"; } } } }catch(SqlException ex) { form1.InnerText += ex.Message; } catch (InvalidOperationException ex) { form1.InnerText += ex.Message; } }
Dove sbaglio?
Ringrazio tutti coloro che mi daranno una mano e se potessero anche controllare se il resto del codice � scritto bene

Rispondi quotando

