Dopo vari tentativi mi sento allo stesso modo del tizio che nei forum scrive “I am really frustrated with SQL Azure” (tra l’altro se cercate “connect sql management” troverete un sacco di gente che ha sto problema…”)

Morale della favola: non riesco a connettermi con uno strumento umano come Sql Management o Visual Studio, le ho provate tutte ma riesco solo con  il tool sqlcmd.

Per connettermi con l’sqlcmd:

sqlcmd  -S tcp:****.database.windows.net -U Babbawg@**** -P miapassword -d nomedatabase

Esempio di utilizzo:

CREATE TABLE TabNames(cod int NOT NULL, des varchar(50) NULL)
GO
CREATE UNIQUE CLUSTERED INDEX Idx1 ON TabNames (cod)
GO
INSERT INTO TabNames VALUES (1, 'Paolo Ongari')
GO
SELECT * FROM TabNames
GO

Da codice funziona correttamente:

  1. private void Test()
  2. {
  3.     string strConn = "Server=tcp:****.database.windows.net;Database=nomedb;User ID=Babbawg@****;Password=****;Trusted_Connection=False;";
  4.  
  5.     using (SqlConnection conn = new SqlConnection(strConn))
  6.     {
  7.         conn.Open();
  8.         using (SqlCommand comm = new SqlCommand("SELECT cod, des FROM TabNames", conn))
  9.         {
  10.             SqlDataReader reader = comm.ExecuteReader();
  11.             while (reader.Read())
  12.             {
  13.                 int id = reader.GetInt32(0);
  14.                 string name = reader.GetString(1);
  15.                 Console.WriteLine("Id={0}, Nome={1}", id.ToString(), name);
  16.             }
  17.         }
  18.         conn.Close();
  19.     }
  20. }
  21.  
 

Prima che mi ritorni la voglia di riprovare aspetterò un po…