 |
|
error เกิดข้อผิดพลาดในการเชื่อมต่อฐานข้อมูลค่ะ error dr = Com.ExecuteReader |
|
 |
|
|
 |
 |
|
error เกิดข้อผิดพลาดในการเชื่อมต่อฐานข้อมูลค่ะ error dr = Com.ExecuteReader ต้องแก้ไขยังไงค่ะ รบกวนช่วยแนะนำหน่อยค่ะ
เพราะว่ารันในเครื่องอื่นได้ แต่รรันในเครื่องของเรารันไม่ได้ติดปัญหา dr = Com.ExecuteReader
Code (VB.NET)
Imports System.IO 'เนมสเปซกลุ่มออบเจ็กต์ IO
Imports System.Text 'เนมสเปซของออบเจ็กต์ StringBuilder
Imports System.Data.OleDb 'เนมสเปซกลุ่มออบเจ็กต์ OleDb
Imports System.Security.Cryptography
Public Class frmLogin
Dim conn As New OleDbConnection() 'ตัวแปรออบเจ็กต์ OleDbConnection
Dim Invalid As Integer = 0 'ตัวแปร Invalid เก็บจำนวนครั้งที่ Login ผิด
Dim TmpRowsAffected As Long = 0 'ตัวแปร TmpRowsAffected เก็บแถวที่มีผลกระทบ
Dim tmpUserName As String 'ตัวแปร tmpUserName เก็บ Username ชั่วคราว
Dim xmlFilePhat As String = "C:\\UserLogFile.xml" 'ตัวแปร xmlFilePhat ที่เก็บ File .xml
Dim isfind As Boolean = False 'ตัวแปร isfind ตรวจสอบการกำหนดสถานะ
Private Sub LoginForm1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strconn As String 'ตัวแปรเก็บข้อความเชื่อมต่อกับฐานข้อมูล
strconn = ConnectDB.StrConn 'อ่านข้อความเชื่อมต่อกับฐานข้อมูลจากคลาส ConnectDb
With conn 'เริ่มเชื่อมต่อกับฐานข้อมูล
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strconn
.Open() 'เชื่อมต่อกับฐานข้อมูล
End With
'MyNewSub() 'กำหนดให้ฟอร์มใส
'clear textbox
txtUsername.Focus()
txtUsername.Text = ""
txtPassword.Text = ""
txtUserLogin.Hide()
txtLevels_id.Hide()
End Sub
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_OK.Click
'OK botton login เข้าสู่ระบบ
Dim sb As New StringBuilder() 'ตัวแปรออบเจกต์ StringBuilder ที่ชื่อว่า sb
Dim tmpPassword As String
If txtUsername.Text = "" Or txtPassword.Text = "" Then 'เช็ดค่าว่างใน textbox
MessageBox.Show("กรุณากรอกชื่อ และ รหัสผ่านด้วยค่ะ", "แจ้งเตือนจากระบบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtUsername.Focus()
Exit Sub
End If
'ทำการเลือกข้อมูลจากตาราง Committee
sb.Append("SELECT [Committee_id], [Pass] FROM [Committee]")
sb.Append("WHERE ([Committee_id]=@Committee_id)")
sb.Append("AND ([Pass]=@Pass)")
sb.Append("AND ([IsNormal]='1')") 'ใช้งานได้ตามปกติ
Dim Username As New OleDbParameter("@Committee_id", OleDbType.VarChar)
Dim Password As New OleDbParameter("@Pass", OleDbType.VarChar)
Dim sqlLogin As String 'สร้างชุดคำสั่ง sqlLogin เก็บคำสั่ง sql
sqlLogin = sb.ToString()
Dim Com As New OleDbCommand() 'ตัวแปรออบเจ็กต์ OleDbCommand
Dim dr As OleDbDataReader 'ตัวแปรออบเจ็กต์ OleDbDataReader
tmpPassword = MD5(txtPassword.Text)
txtPassword.Text = tmpPassword
With Com
.CommandType = CommandType.Text
.CommandText = sqlLogin 'ใช้ชุดคำสั่ง sqlLogin
.Connection = conn 'เชื่อมต่อฐานข้อมูล
.Parameters.Clear()
.Parameters.Add(Username).Value = txtUsername.Text 'ตรวจสอบชื่อผู้ใช้งาน
.Parameters.Add(Password).Value = txtPassword.Text 'ตรวจสอบรหัสผ่าน
dr = Com.ExecuteReader 'error ตรงบรรทัดนี้ค่ะ
If dr.HasRows Then 'กรณีพบข้อมูล
isfind = True 'กำหนดสถานะเป็น True
Invalid = 0 'จำนวนครั้งที่ Login ผิด เท่ากับ 0
Call CheckUserLogin() 'เรียกซับรูทีน CheckUserLogin() ทำงาน
MessageBox.Show("ยินดีต้อนรับคุณ: " & txtUserLogin.Text & " เข้าสู่ระบบค่ะ", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
Call WriteLogFile1() 'เรียกซับรูทีน writelogfile1() ทำงาน
txtUsername.Text = ""
txtPassword.Text = ""
Dim fMain As New frmmain
fMain.Show() 'ทำการเปิด frmMain()
Me.Hide()
tmpUserName = txtUsername.Text
Else 'กรณีไม่พบข้อมูล
isfind = False 'กำหนดสถานะเป็น False
WriteLogFile() 'เรียกซับรูทีน writelogfile() ทำงาน
If Invalid = 3 Then
UpdateInvalidUser() 'เรียกซับรูทีน UpdateinvalidUser() ทำงาน
If TmpRowsAffected <> 0 Then
MessageBox.Show("ชื่อผู้ใช้งานนี้ไม่สามารถใช้งานได้ชั่วคราว กรุณาติดต่อ: ผู้ดูแลระบบค่ะ", "แจ้งเตือนจากระบบ", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtUsername.Text = ""
txtPassword.Text = ""
txtUsername.Focus()
Invalid = 0 'จำนวนครั้งที่ Login ผิด เท่ากับ 0
Exit Sub
End If
End If
MessageBox.Show("ไม่มีผู้ใช้งานนี้ในระบบค่ะ", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtUsername.Text = ""
txtPassword.Text = ""
txtUsername.Focus()
End If
End With
End Sub
Tag : .NET, Ms Access
|
|
 |
 |
 |
 |
Date :
2011-03-12 11:05:29 |
By :
ict |
View :
5377 |
Reply :
17 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อืม ต้องรอผู้รู้มาตอบแล้วล่ะ
|
 |
 |
 |
 |
Date :
2011-03-12 17:27:27 |
By :
chilchil |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่เอา message error มาให้ดูด้่วยล่ะ ว่ามัน error ว่าอะไร
|
 |
 |
 |
 |
Date :
2011-03-12 17:56:55 |
By :
salapao_codeman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ค่ะ เกิด error แบบนี้ค่ะ แก้ไขยังไม่ได้เลยค่ะ ช่วยแนะนำหน่อยค่ะ แต่รันเครื่องอื่นได้ แต่รันเครื่องเราไม่ได้ ต้องไปตั้งค่าอะไรไหมค่ะ ใช้ vb 2008 ค่ะ

|
 |
 |
 |
 |
Date :
2011-03-15 14:25:43 |
By :
ict |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เอิ๊ก ๆ ๆ ตอนนี้ก็มีปัญหา ยุ...
|
 |
 |
 |
 |
Date :
2011-03-15 14:39:37 |
By :
termja |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันบอกว่า ให้เปิด Connection ครับ เนื่องจากไม่ได้เปิด หรือถูกปิดไปแล้ว
|
 |
 |
 |
 |
Date :
2011-03-15 14:45:28 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ต้องเขียนโค้ดยังไงค่ะ ช่วยหน่อยจ้า ไม่ได้มาหลายวันแล้วค่ะ
|
 |
 |
 |
 |
Date :
2011-03-15 18:38:28 |
By :
ict |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูนะครับ เผื่อแก้ไขได้
ไม่แน่ใจ เนื่องจากเห็นบอกว่าเปิดที่เครื่องอื่นไม่มีปัญหา


|
 |
 |
 |
 |
Date :
2011-03-15 20:20:48 |
By :
base3000 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำตามที่คุณ tong บอกแล้วก็ยังเกิด error อยู่ค่ะ แบบนี้ค่ะ มันหมายถึงอะไรค่ะ

|
 |
 |
 |
 |
Date :
2011-03-16 18:44:00 |
By :
ict |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ติด error ตรงนนี้เหมือนกันครับ ถ้าใช้ตัวอื่นแทน ต้องใช้อะไรครับ อยากทราบครับ
|
 |
 |
 |
 |
Date :
2011-03-16 20:30:58 |
By :
hoo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Project properties เลือก Tab Compile เลือ Button Advanced Compile Options ที่ Target CPU เลือกเป็น x86

|
 |
 |
 |
 |
Date :
2011-03-17 15:20:44 |
By :
hoo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วยบอกวิธีแก้ปัญหาเกิดจากอะไรค่ะ

|
 |
 |
 |
 |
Date :
2011-05-24 14:04:03 |
By :
may |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
dr = com.ExecuteReader() 'อ่านข้อมูล error ในปุ่มบันทึกข้อมูลค่ะ อยากทราบว่าต้องแก้อย่างไร
|
 |
 |
 |
 |
Date :
2012-09-28 21:16:06 |
By :
ศันศนีย์ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2013-09-11 01:16:13 |
By :
mmm |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

โค้ดค่ะ
Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Text;
namespace AspNetMember
{
public partial class frmUpdateProfile : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//*** Check login Status ***'
if (Convert.ToString(Session["strUsername"]) == "")
{
Response.Redirect("frmLogin.aspx");
Response.End();
}
this.pnlProfile.Visible = true;
this.pnlFinish.Visible = false;
if (!Page.IsPostBack)
{
ShowDataInfo();
}
}
protected void ShowDataInfo()
{
SqlConnection objConn = null;
string strConnString = null;
StringBuilder strSQL = default(StringBuilder);
SqlCommand objCmd = null;
SqlDataReader dtReader = null;
//*** Open Connection ***'
strConnString = "Data Source=JUNE-PC;Initial Catalog=mydatabase;Integrated Security=True";
objConn = new SqlConnection();
objConn.ConnectionString = strConnString;
objConn.Open();
//*** Get Data ***'
strSQL = new StringBuilder();
strSQL.Append(" SELECT * FROM membergun ");
strSQL.Append(" WHERE Username = @sUsername ");
objCmd = new SqlCommand(strSQL.ToString(), objConn);
objCmd.Parameters.Add("@sUsername", SqlDbType.VarChar).Value = Session["strUsername"];
dtReader = objCmd.ExecuteReader();
if (dtReader.HasRows)
{
dtReader.Read();
this.lblUsername.Text = dtReader["Username"].ToString();
this.txtName.Text = dtReader["Name"].ToString();
this.txtAge.Text = dtReader["Age"].ToString();
this.txtVocation.Text = dtReader["Vocation"].ToString();
this.txtWorkplace.Text = dtReader["Workplace"].ToString();
this.txtAddress.Text = dtReader["Address"].ToString();
this.txtPhone.Text = dtReader["Phone"].ToString();
this.txtEmail.Text = dtReader["Email"].ToString();
}
dtReader.Close();
objConn.Close();
objConn = null;
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
SqlConnection objConn = null;
string strConnString = null;
StringBuilder strSQL = default(StringBuilder);
SqlCommand objCmd = null;
int intCount = 0;
//*** Open Connection ***//
strConnString = "Data Source=JUNE-PC;Initial Catalog=mydatabase;Integrated Security=True";
objConn = new SqlConnection();
objConn.ConnectionString = strConnString;
objConn.Open();
//*** Check Email exists ***//
strSQL = new StringBuilder();
strSQL.Append(" SELECT COUNT(*) FROM membergun ");
strSQL.Append(" WHERE Email = @sEmail AND Username <> @sUsername");
objCmd = new SqlCommand(strSQL.ToString(), objConn);
objCmd.Parameters.Add("@sEmail", SqlDbType.VarChar).Value = this.txtEmail.Text;
objCmd.Parameters.Add("@sUsername", SqlDbType.VarChar).Value = Session["strUsername"];
intCount = (int)objCmd.ExecuteScalar();
if (intCount >= 1)
{
this.lblStatus.ForeColor = System.Drawing.Color.Red;
this.lblStatus.Text = "Email already exists!!";
return;
}
//'*** Update Profile ***//
strSQL = new StringBuilder();
strSQL.Append(" UPDATE membergun ");
strSQL.Append(" SET Password = @sPassword ");
strSQL.Append(" ,Name = @sName ");
strSQL.Append(" ,Age = @sAge ");
strSQL.Append(" ,Vocation = @sVocation ");
strSQL.Append(" ,Workplace = @sWorkplace ");
strSQL.Append(" ,Address = @sAddress ");
strSQL.Append(" ,Phone = @sPhone ");
strSQL.Append(" ,Email = @sEmail ");
strSQL.Append(" WHERE Username = @sUsername");
objCmd = new SqlCommand(strSQL.ToString(), objConn);
objCmd.Parameters.Add("@sPassword", SqlDbType.VarChar).Value = this.txtPassword.Text;
objCmd.Parameters.Add("@sName", SqlDbType.VarChar).Value = this.txtName.Text;
objCmd.Parameters.Add("@sAge", SqlDbType.VarChar).Value = this.txtAge.Text;
objCmd.Parameters.Add("@sVocation", SqlDbType.VarChar).Value = this.txtVocation.Text;
objCmd.Parameters.Add("@sWorkplace", SqlDbType.VarChar).Value = this.txtWorkplace.Text;
objCmd.Parameters.Add("@sAddress", SqlDbType.VarChar).Value = this.txtAddress.Text;
objCmd.Parameters.Add("@sPhone", SqlDbType.VarChar).Value = this.txtPhone.Text;
objCmd.Parameters.Add("@sEmail", SqlDbType.VarChar).Value = this.txtEmail.Text;
objCmd.Parameters.Add("@sUsername", SqlDbType.VarChar).Value = Session["strUsername"];
objCmd.ExecuteNonQuery();
objConn.Close();
objConn = null;
this.pnlProfile.Visible = false;
this.pnlFinish.Visible = true;
}
protected void txtAge_TextChanged(object sender, EventArgs e)
{
}
}
}
|
 |
 |
 |
 |
Date :
2016-02-08 04:15:04 |
By :
june |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|