Windows モバイル アプリケーションを開発しています。ローカル データベースをサーバー データベースに接続したいと考えています。デバイスは LAN 接続を持っています。これら 2 つを接続するにはどうすればよいですか。リンクを教えてください。
1386 次
2 に答える
0
SQL Server(ローカルではSQLCE Serverではない)に接続する場合は、最初にデータとsqlclient名前空間をインポートする(そしてプロジェクトへの参照を追加する)必要があります。
using System.Data;
using System.Data.SqlClient;
次に、接続文字列を作成する必要があります。
// Connection string
private string strConn =
"data source=OurServer;" +
"initial catalog=Northwind;" +
"user id=DeliveryDriver;" +
"pwd=DD;" +
"workstation id=OurDevice;" +
"packet size=4096;" +
"persist security info=False;";
次に、接続を作成できます。
// A connection, a command, and a reader
SqlConnection connDB = new SqlConnection(strConn);
SQLクエリ(つまり、「SELECT * FROMProducts;」)を使用してSQLCommandを作成します。
SqlCommand cmndDB =new SqlCommand(sqlQueryString, connDB);
次に、データリーダーを使用して結果を読み取ることができます。
SqlDataReader drdrDB;
結果を読んでください:
try
{
// Open the connection.
connDB.Open();
// Submit the SQL statement and receive
// the SqlReader for the results set.
drdrDB = cmndDB.ExecuteReader();
// Read each row.
while ( drdrDB.Read() )
{
//access fields of the result
}
drdrDB.Close();
}
...
//Close the connection
connDB.Close();
以上です。
于 2012-11-30T18:07:39.823 に答える
0
まず、以下のスクリーンショットに示すように、デバイスがサーバーを参照できることを確認します。
ユーザー名とパスワードを使用してサーバーにアクセスできるようになったら、SQL接続文字列で同じユーザー名とパスワードを使用します。
必要なのはそれだけです。
于 2012-11-30T15:16:44.540 に答える