これはC#で(Connection Pooling用)を使用するためのサンプルコードです。今、私はそれが方法にないために私にエラーを与えていると思います。しかし、これを回避する方法はありますか?今のエラーを与える行であるODBC/MySqlを使用した場合の問題
<% @Page Language="C#" %>
<% @Import Namespace="System.Data.Odbc" %>
<% @Import Namespace="System.Web.Configuration" %>
<script language="C#" runat="server">
string conString = WebConfigurationManager.ConnectionStrings["cheese"].ConnectionString;
using (OdbcConnection con = new OdbcConnection(conString)) {
con.Open();
using (OdbcCommand com = new OdbcCommand("SELECT pies FROM ducks WHERE isapie = nope", con)) {
com.Parameters.AddWithValue("@var", paramWord);
using (OdbcDataReader reader = com.ExecuteReader()) {
while (reader.Read()) {
Response.Write(reader.GetString(0));
}
}
}
con.Close();
}
</script>
:私が編集しやすく、最小限の私のコードを維持しようとしています
Compiler Error Message: CS1519: Invalid token 'using' in class, struct, or interface member declaration
、:
Line 8: using (OdbcConnection con = new OdbcConnection(conString)) {
、問題のエラーです私はそれらを持つために単に不必要なクラス、メソッドなどを避けたいと思っています。
最初に、 'con.Open();'の後ろにある '閉じる'中かっこを 'con.Close();'の後ろに移動する必要があります。あなたはそれを終える前に接続を破棄しています。 –
完了して編集しました。同じ行に同じエラーがあります。 –