ADO.NET関連
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
|
ログイン
] [
Twitter
]
開始行:
→.NETプログラミング
→データベース関連
#contents
*Tips [#q0cfd467]
-Windows認証で接続したいとき
--接続文字列に Integrated Security=SSPI を追加する
--http://www.microsoft.com/japan/msdn/sqlserver/columns/A...
-[[バイナリデータの入出力>http://support.microsoft.com/de...
-SqlCommandのパラメータとOleDbCommandのパラメータの渡し方...
--SqlCommandの場合
---プレースホルダは "@xxx"とし、SqlParameterの名前にも"@x...
--OleDbCommandの場合
---プレースホルダは "?" とし、OleDbParameterの名前にはフ...
--OleDbCommandに対してSqlCommandのやり方でパラメータを渡...
-DataSetのDataRowからカラム名(列名、フィールド名)を取得...
--row.Table.Columns[i].ColumnNameを参照する
-SqlConnectionで接続プールをオフにするには接続文字列に "P...
--SqlConnectionはOleDbConnectionとは微妙に違うので注意
-ADO.NETの接続文字列の簡単な作り方
--新規テキストファイルを作成し、拡張子を「udl」(OLE DB U...
後は、ウィザードに従って入力していけば、ファイルの中に接...
--ソース:http://www.vacant-eyes.jp/Tips/tadonet.html
-更新系SQLを文字列編集の際の注意
--こういうコードを書いたらダメ
void LogUserName(SqlConnection conn, string userName) {
string sqlText = "insert user_names values('" + userNa...
SqlCommand cmd = new SqlCommand(sqlText, conn);
cmd.ExecuteNonQuery();
}
--userNameに何が入ってくるかわからないから(いわゆるSQLイ...
--例えば ''名前','その隣の項目に入れたい値'' という文字列...
--パラメータを使うこと
void LogUserName(SqlConnection conn, string userName) {
string sqlText = "insert user_names values(@n)";
SqlCommand cmd = new SqlCommand(sqlText, conn);
SqlParameter p = cmd.Parameters.Add("@n", SqlDbType.Va...
p.Value = userName;
cmd.ExecuteNonQuery();
}
-SqlCommandの例外を拾うときはSqlExceptionでやった方が多少...
*パフォーマンス [#k540827e]
-[[Connection Pooling at a Glance>http://www.codeproject....
-[[ADO.NETのパフォーマンス調査:http://www.devx.com/vb2the...
--SQLClientDataReaderが最速との結果
-[[ADO.NET パフォーマンスの向上@MSDN:http://www.microsoft...
*SQL Serverに接続すると General network error. Check you...
-OLE DBで無効なコネクションがプールされることから起きる模様
-こちらを参照:http://support.microsoft.com/?scid=kb%3Ben-...
-CAUSE
In the current design, after an application role is enab...
you cannot reset the security context of that connection...
the SQL Server session and disconnects from the server, ...
However, OLE DB resource pooling returns the closed conn...
and the error occurs when that connection is reused and ...
the connection's security context by calling sp_setappro...
-WORKAROUND
The only available workaround is to disable OLE DB Resou...
You can do this by adding "OLE DB Services = -2" to the ...
-サンプル
'For SQLOLEDB provider
'strConnect = "Provider=SQLOLEDB;server=SQL7Web;OLE DB S...
initial catalog=northwind"
' For MSDASQL provider
'strConnect = "DSN=SQLNWind;UID=Test;PWD=Test; OLE DB Se...
Pooling can be disabled for the SQL Server .Net Data Prov...
"Pooling=False" to the connection string.
-ただし、SQLConnectionクラスを使ってる場合、"OLE DB Servi...
*その他 [#fffa5352]
-[[ADO.NET 2.0の接続文字列の管理問題>http://www.digitaldj...
--.NET 2.0では接続文字列の管理場所がappSettings要素からco...
終了行:
→.NETプログラミング
→データベース関連
#contents
*Tips [#q0cfd467]
-Windows認証で接続したいとき
--接続文字列に Integrated Security=SSPI を追加する
--http://www.microsoft.com/japan/msdn/sqlserver/columns/A...
-[[バイナリデータの入出力>http://support.microsoft.com/de...
-SqlCommandのパラメータとOleDbCommandのパラメータの渡し方...
--SqlCommandの場合
---プレースホルダは "@xxx"とし、SqlParameterの名前にも"@x...
--OleDbCommandの場合
---プレースホルダは "?" とし、OleDbParameterの名前にはフ...
--OleDbCommandに対してSqlCommandのやり方でパラメータを渡...
-DataSetのDataRowからカラム名(列名、フィールド名)を取得...
--row.Table.Columns[i].ColumnNameを参照する
-SqlConnectionで接続プールをオフにするには接続文字列に "P...
--SqlConnectionはOleDbConnectionとは微妙に違うので注意
-ADO.NETの接続文字列の簡単な作り方
--新規テキストファイルを作成し、拡張子を「udl」(OLE DB U...
後は、ウィザードに従って入力していけば、ファイルの中に接...
--ソース:http://www.vacant-eyes.jp/Tips/tadonet.html
-更新系SQLを文字列編集の際の注意
--こういうコードを書いたらダメ
void LogUserName(SqlConnection conn, string userName) {
string sqlText = "insert user_names values('" + userNa...
SqlCommand cmd = new SqlCommand(sqlText, conn);
cmd.ExecuteNonQuery();
}
--userNameに何が入ってくるかわからないから(いわゆるSQLイ...
--例えば ''名前','その隣の項目に入れたい値'' という文字列...
--パラメータを使うこと
void LogUserName(SqlConnection conn, string userName) {
string sqlText = "insert user_names values(@n)";
SqlCommand cmd = new SqlCommand(sqlText, conn);
SqlParameter p = cmd.Parameters.Add("@n", SqlDbType.Va...
p.Value = userName;
cmd.ExecuteNonQuery();
}
-SqlCommandの例外を拾うときはSqlExceptionでやった方が多少...
*パフォーマンス [#k540827e]
-[[Connection Pooling at a Glance>http://www.codeproject....
-[[ADO.NETのパフォーマンス調査:http://www.devx.com/vb2the...
--SQLClientDataReaderが最速との結果
-[[ADO.NET パフォーマンスの向上@MSDN:http://www.microsoft...
*SQL Serverに接続すると General network error. Check you...
-OLE DBで無効なコネクションがプールされることから起きる模様
-こちらを参照:http://support.microsoft.com/?scid=kb%3Ben-...
-CAUSE
In the current design, after an application role is enab...
you cannot reset the security context of that connection...
the SQL Server session and disconnects from the server, ...
However, OLE DB resource pooling returns the closed conn...
and the error occurs when that connection is reused and ...
the connection's security context by calling sp_setappro...
-WORKAROUND
The only available workaround is to disable OLE DB Resou...
You can do this by adding "OLE DB Services = -2" to the ...
-サンプル
'For SQLOLEDB provider
'strConnect = "Provider=SQLOLEDB;server=SQL7Web;OLE DB S...
initial catalog=northwind"
' For MSDASQL provider
'strConnect = "DSN=SQLNWind;UID=Test;PWD=Test; OLE DB Se...
Pooling can be disabled for the SQL Server .Net Data Prov...
"Pooling=False" to the connection string.
-ただし、SQLConnectionクラスを使ってる場合、"OLE DB Servi...
*その他 [#fffa5352]
-[[ADO.NET 2.0の接続文字列の管理問題>http://www.digitaldj...
--.NET 2.0では接続文字列の管理場所がappSettings要素からco...
ページ名: