我使用MySQL在C#ASP.NET中创建项目。我试图正确打开MySql连接。也正确关闭/处理此连接。因为它有时会出现错误
“mySQL错误:系统缺少足够的缓冲区空间或因为队列 满满的。“
无论如何所以我决定使用“使用”方法我当前的连接方法;
MySqlConnection baglanti = new MySqlConnection(ConfigurationManager.ConnectionStrings["mysqlbaglanti"].ToString());
void GirisYap()
{
using (var cn = baglanti)
{
cn.Open();
using (MySqlCommand cmd = new MySqlCommand("SELECT * FROM kullanicilar WHERE kullaniciadi='" + txtKullaniciAdi.Text + "' AND sifre='" + txtSifre.Text + "'"))
{
using (MySqlDataReader oku = cmd.ExecuteReader())
{
if (oku.Read())
{
Session.Add("AdSoyad", oku["AdSoyad"]);
Session.Add("sesid", oku["kullaniciid"]);
Response.Redirect("AnaSayfa.aspx");
}
else
{
lblDurum.Text = "Yanlış Kullanıcı Adı/Şifre !";
}
}
}
}
}
但是它给出了“连接必须有效并且打开”的错误。我做错了什么?
答案 0 :(得分:1)
const path = require('path');
const glob = require('glob');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const WebpackMd5Hash = require('webpack-md5-hash');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin')
module.exports = {
entry: { main: glob.sync('./src/**/*.js*')} ,
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'main.js',
},
devtool: 'inline-source-map',
watch: true,
module: {
rules: [
{
test: /\.pug$/,
use: ["html-loader", "pug-html-loader"]
},
{
test: /\.js$/,
exclude: /node_modules/,
use: ["babel-loader"]
},
{
test: /\.scss$/,
use: ExtractTextPlugin.extract(
{
fallback: 'style-loader',
use: [ 'css-loader', 'sass-loader']
})
},
{
type: 'javascript/auto',
test: /\.json$/,
use: [
{
loader: 'file-loader',
options: {
name: "./plugin-config/[name].[ext]"
}
}
]
}
]
},
devServer: {
contentBase: path.join(__dirname, "dist"),
compress: true,
inline: true,
port: 3000,
// historyApiFallback: true,
hot: true
},
plugins: [
new ExtractTextPlugin(
{ filename: 'style.css'}
),
new CleanWebpackPlugin('dist', { watch: true,
}),
new HtmlWebpackPlugin({
inject: false,
hash: true,
template: './src/index.html',
}),
new WebpackMd5Hash(),
]
};
中你应该创建新的using
对象。当您使用范围退出时,它将被处理。
在您的代码中,您在类对象构造期间生成连接。首次使用IDisposible
后,您的cn
对象将被处置。首次使用后,您无法打开连接。因此,您应该在using语句中生成连接对象。
以上都是建议,而不是您问题的解决方案。您的问题是,命令对象没有连接对象。您可以通过构造函数
将connectin对象传递给命令对象你应该使用:
baglanti