このリンクに基づく:http://msdn.microsoft.com/en-us/library/windowsazure/ee336243.aspx
このコードを使用してSQLAzureデータベースに接続し、行を挿入しようとしています。
// The values being assigned to the StringBuilder members are set previously/not shown
SqlConnectionStringBuilder connStringBuilder = new SqlConnectionStringBuilder();
connStringBuilder.DataSource = dataSource;
connStringBuilder.InitialCatalog = databaseName;
connStringBuilder.Encrypt = true;
connStringBuilder.TrustServerCertificate = false;
connStringBuilder.UserID = userName;
connStringBuilder.Password = password;
using (SqlConnection conn = new SqlConnection(connStringBuilder.ToString()))
{
using (SqlCommand command = conn.CreateCommand())
{
conn.Open();
command.CommandText =
"INSERT INTO T1 (col1, col2) values (1, 'string 1'), (2, 'string 2'), (3, 'string 3')";
int rowsAdded = command.ExecuteNonQuery();
}
conn.Close();
}
しようとすると、つまり-SqlConnectionStringBuilder, SqlConnection
であり、SqlCommand
認識/解決できません。これを機能させるには、別のADO.NETパッケージをインストールする必要がありますか?
アップデート
System.Data.dll
プロジェクト参照(私のマシン上で、から
)に追加することでC:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5
、これらのクラスを認識/解決することができますが、それでもコンパイル時エラーが発生します。
エラー1アセンブリ'System、Version = 4.0.0.0、Culture = neutral、PublicKeyToken =b77a5c561934e089'の基本クラスまたはインターフェイス'System.ComponentModel.Component'は、タイプ'System.Data.Common.DbConnection'で解決できませんでしたc :\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETFramework \ v4.5 \ System.Data.dll
と:
エラー2アセンブリ'System、Version = 4.0.0.0、Culture = neutral、PublicKeyToken =b77a5c561934e089'の基本クラスまたはインターフェイス'System.ComponentModel.Component'は、タイプ'System.Data.Common.DbCommand'によって解決できませんでしたc :\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETFramework \ v4.5 \ System.Data.dll
更新2
参照としてSQL.Dataを追加すると、さまざまなタイプを解決できましたが、別の問題により、アプリをコンパイルできませんでした。
モジュールmscorlib.dllにタイプSystem.SystemExceptionが見つかりません
参照からSQL.Dataを削除すると、その問題が解消されました。