wex5連接資料庫
『壹』 win10 電腦wex5登錄資料庫連接失敗Access denied for user 'root'@'localhost' (u
如果登鏈肢錄資料庫失敗的話,緩喚鄭還是先需要重啟一下,伺服器或者是把電腦進行重啟一下,在嘗試不行的話就需要重新安裝了。擾頌
『貳』 web界面怎麼和資料庫相連的
我寫的C#簡單實例,希望對您有幫助:
比如在網頁中的一個標簽框為Label1來顯示連接 SQL Server 2005 資料庫是否成功,下面是業務邏輯代碼:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;//引用專用於連接SQLServer資料庫的SqlClient
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)//頁面載入時的方法
{
string ConnectionString = "Server=(local)\\資料庫實例;UId=登錄賬號;Pwd=密碼;Database=資料庫名稱";//連接資料庫的string
SqlConnection conn = new SqlConnection(ConnectionString);
SqlCommand sc = new SqlCommand();
sc.CommandText = "SELECT * FROM 表名";//查詢語句
try
{
conn.Open();//打開資料庫的連接
Label1.Text = "資料庫連接成功";
}
catch
{
Label1.Text = "資料庫連接失敗";
}
finally
{
conn.Close();//關閉資料庫的連接
}
}
}
在Visual Web Developer 2005 Express 版編譯通過
『叄』 wex5怎麼連接資料庫
//初始化資料庫連接
::CoInitialize(NULL);
連接資料庫
[cpp] view plainprint?
BOOL CLogin::ConnectDB(void)
{
HRESULT hr = NULL;
鎮團try
御差橘{
hr = m_pConnection.CreateInstance("ADODB.Connection");///創建 Connection 對象
if(SUCCEEDED(hr))
{
//登錄資料庫並連接資料庫DBCourse
//這里的server不能寫成127.0.0.1否則會出現未指定的錯誤,應該寫成Sql server登錄界面的伺服器名稱
m_pConnection->ConnectionString = "driver={SQL Server};server=LOGO-PC\\LOGO;uid=DBCourse;pwd=DBCourse;";
m_pConnection->Open("","","",adConnectUnspecified);
m_pConnection->DefaultDatabase = "DBCourse";
}
else
{
AfxMessageBox(TEXT("創建 Connection 對象失敗"));///顯示錯誤信息
return FALSE;
}
}
catch(_com_error e)///捕捉異常
{
CString errormessage;
errormessage.Format( TEXT("連接資料庫失敗 !\r\n 錯誤信息 :%s(%ld)"),e.ErrorMessage(),e.Error() );
AfxMessageBox(errormessage);///慶御顯示錯誤信息
return FALSE;
}
return TRUE;
}
操作資料庫
[cpp] view plainprint?
void CLogin::OnBnClickedButton1()
{
if( m_user.GetWindowTextLength()<=0 || m_password.GetWindowTextLength()<=0 )
{
MessageBox(TEXT("請輸入用戶名或密碼!"), TEXT("錯誤:用戶名或密碼為空"), MB_OK | MB_ICONWARNING );
return;
}
if( FALSE==this->ConnectDB() ) return;
TCHAR szUserName[20];
TCHAR szPassword[50];
TCHAR szSql[MAX_PATH];
//獲取用戶輸入的用戶名和密碼
m_user.GetWindowText( szUserName, 20 );
m_password.GetWindowText( szPassword, 50 );
//創建_RecordsetPtr用來執行資料庫操作
_RecordsetPtr pRecordset;
pRecordset.CreateInstance("ADODB.Recordset");
_tcscpy_s( szSql, TEXT("select * from usr where uname='") );
_tcscat_s( szSql, szUserName );
_tcscat_s( szSql, TEXT("' and passwd='") );
_tcscat_s( szSql, szPassword );
_tcscat_s( szSql, TEXT("';") );
pRecordset->Open(_variant_t(szSql), _variant_t ((IDispatch*) m_pConnection,true), adOpenStatic, adLockOptimistic, adCmdText);
int nResult = DLG_RESULT_OK;
if( pRecordset->RecordCount>0 )
{
//MessageBox(TEXT("登錄成功!"), szUserName, MB_OK | MB_ICONINFORMATION );
}
else
{
MessageBox(TEXT("用戶名或密碼錯誤!"), TEXT("登錄失敗!"), MB_OK | MB_ICONINFORMATION );
nResult = DLG_RESULT_ERROR;
}
pRecordset->Close();
if( DLG_RESULT_OK==nResult ) Exit( DLG_RESULT_OK );
}
哦忘了一件事了,還需要在stafx.h文件中引入dll文件的,如此
[cpp] view plainprint?
//添加dll庫
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
//添加dll庫
//添加宏定義
#define DLG_RESULT_OK 1
#define DLG_RESULT_ERROR 2
#define DLG_RESULT_CANCEL 3
//添加宏定義
『肆』 wex5怎麼連接資料庫
首先是在資料庫中將連接數調大一些,另外還有一個重要的問題是:程序與資料庫的操作使用的是JDBC
『伍』 用wex5開發webapp的資料庫怎麼編寫
主要步驟如下:
1、調試絕乎模模式和生產模頃碼式
2、使用WeX5的Tomcat
3、使用自己部署的Tomcat
3.1、設置JAVA_HOME
3.2、設置JUSTEP_HOME
3.3、在Tomcat中部署UIServer
3.4、跳轉到門戶頁
4、部署到WebLogic
4.1、設置JAVA_HOME
4.2、設置JUSTEP_HOME
4.3、在WebLogic中部署並緩UIServer