找到SQL Sever服務。在計算機管理框里找到Sql sever配置管理器找到Sql Sever服務打開服務,這里有幾種服務,這些服務都是自己安裝資料庫時裝上的。
2
打開啟動SQL Sever服務。右鍵點擊服務,這里要看清楚什麼才是服務,小技巧:伺服器的圖標是一個庫的樣式,啟動它就可以了。
END
SQL文件目錄啟動服務(二)
1
找到SQL安裝目錄。點擊【開始】--【所有文件】--【Microsoft SQL Server 2008】--【配置工具】--【SQL Server 配置管理器】。如下圖:
2
在Sql Sever配置管理框開啟服務。下面是資料庫服務配置管理框,找到我們需要使用的資料庫服務,右鍵開啟它,這樣就可以使用了。
END
DOS命令開啟服務(三)
打開DOS命令框。點擊【開始】--【運行】--輸入:CMD 命令。
在命令框輸入字元命令。我們成功打開命令框後,在命令框里輸入:net start mssqlserver 啟動Sql伺服器,同理net stop mssqlserver 是停止伺服器。
恭喜你,成功開啟SQL伺服器。
檢驗是否開啟服務。安裝上面方法一或者二都可以,下面是我的查看的結果:成功開啟服務,如果想關閉服務,使用一行代碼就可以了。溫馨提示下,DOS命令開啟服務有很多容易錯處點,這裡面還有很多知識,更多的可以自己去學習下。
關閉資料庫服務。使用完成後記得關閉服務,很占內存的。關閉方式命令:net stop mssqlserver。效果如下圖看看試試如何:
Ⅱ asp.net 連接SQL資料庫的封裝類,及其調用方法
1.web.config 中
<add key="ConnectionString" value="server=(local);uid=sa;pwd=123456;database=News"/>
調用的時候
string strConn = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"].ToString();
SqlConnection Conn = new SqlConnection(strConn);
2.或者不用web.config直接在文件中寫
SqlConnection conn = new SqlConnection("server=.\\SQLEXPRESS;uid=sa;pwd=123456;database=login");
如何是Express版的資料庫,一定要在伺服器名的後面加上 \\SSQLEXPRESS
Ⅲ 如何使用sqldeveloper連接資料庫
方法/步驟
1
安裝sqldeveloper後,打開客戶端
2
在「文件」菜單中選擇「新建」菜單,快捷鍵CTRL+N,打開「新建庫」對話框
3
在「新建庫」對話框中,類別General中選擇連接,在連接中選擇「資料庫連接」,點擊確定,彈出「新建/選擇資料庫連接」對話框
4
在對話框中輸入資料庫的信息
5
點擊「測試」按鈕,測試連接狀態,連接成功後,會提示狀態是成功的
6
測試成功後,點擊「連接」按鈕,成功連接資料庫。在右側的空白處,可以輸入資料庫語言操作資料庫了。
http://jingyan..com/article/d621e8da366c6d2864913f70.html
Ⅳ php.封裝資料庫連接,主要實現excuteSql執行sql語句,getReader查詢函數。
可以的。
<?
functionget_user(){
$sql="select*fromuser";
$result=mysql_query($sql);
$arr=array();
while($rows=mysql_fetch_assoc($reslut)){
$arr[]=$rows;
}
return$arr;
}
$user=get_suer();
print_r($user);
?>
Ⅳ 9.6 如何封裝sql 資料庫命令舉例
做成 存儲過程
create procere sp_procere --創建存儲過程
(@key varchar(10)) --設置傳遞的參數(可以沒有)
as
begin
--需封裝的sql語句
end
運行該存儲過程
exec sp_procere 參數
Ⅵ sql怎樣連接資料庫
.代表你連接的資料庫所是在本機上的,也可以寫成127.0.0.1\\sqlexpress
如果你寫成別的代表你所連接的資料庫在別的電腦上,即遠程連接
例如:server=某一電腦的
ip(這個時候就只要寫server=ip,也可以寫成server=ip\\sqlexpress)
希望對你有所幫助
Ⅶ 怎麼把sql的資料庫封裝成CDatabaseAccess類
可以參考一下這個:
使用CDatabase類來讀取Microsoft Access資料庫,主要實現了以下功能:
從Microsoft Access 資料庫讀取數據
不使用ODBC數據源進行資料庫連接
在List view控制項中顯示數據
// 以下是部分代碼
void CReadDBDlg::OnRead()
{
// TODO: Add your control notification handler code here
CDatabase database;
CString sSql;
CString sCatID, sCategory;
CString sDriver = "MICROSOFT ACCESS DRIVER (*.mdb)";
CString sDsn;
CString sFile = "c:\\works\\ReadDB\\Test.mdb"; // Change path here
int iRecord = 0;
// Create a pseudo DSN including the name of the Driver and the Excel file
// so we donhave to have an explicit DSN installed in our ODBC admin
sDsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s",sDriver,sFile);
TRY
{
// Open the database
database.Open(NULL,false ,false ,sDsn);
// the recordset
CRecordset recset( &database );
// Build the SQL query string
sSql = "SELECT CatID, Category "
"FROM Categories";
// Execute the query)
recset.Open(CRecordset::forwardOnly,sSql,CRecordset::readOnly);
ResetListControl();
// Column heading
m_ListControl.InsertColumn(1,"Cat ID",LVCFMT_LEFT,30,0);
m_ListControl.InsertColumn(1,"Category",LVCFMT_LEFT,30,1);
// Browse the result
while ( !recset.IsEOF() )
{
// Read one record
recset.GetFieldValue("CatID",sCatID);
recset.GetFieldValue("Category",sCategory);
// Insert values into the list control
m_ListControl.InsertItem(0,sCatID,0);
m_ListControl.SetItemText(0,1,sCategory);
// goto next record
recset.MoveNext();
}
// Close the database
database.Close();
}
CATCH(CDBException, e)
{
// If a database exception occured, pop up error msg
AfxMessageBox("Database error: "+e->m_strError);
}
END_CATCH;
}
void CReadDBDlg::ResetListControl()
{
m_ListControl.DeleteAllItems();
int iNbrOfColumns;
CHeaderCtrl* pHeader = (CHeaderCtrl*)m_ListControl.GetDlgItem(0);
if (pHeader)
{
iNbrOfColumns = pHeader->GetItemCount();
}
for (int i = iNbrOfColumns; i >= 0; i--)
{
m_ListControl.DeleteColumn(i);
}
}
Ⅷ 如何將SQL的資料庫連接封裝到DLL中
使用C#生成dll文件並調用
一、創建dll文件:
例如生成一個md5編碼判斷狀態的文件,即,輸入一個字元串(string A)和一個32位md5編碼(string B),判斷此字元串A對應的32位md5編碼是否與B相等,如果相等返回true,否則返回false。
打開VS 2005,「文件」--》「新建」--「項目」,選擇「Windows 控制項庫」,命名後點擊「確定」,在「UserControl1.cs」中輸入以下代碼:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Text;
using System.Security.Cryptography;
namespace md5
{
public partial class Program : UserControl
{
#region MD5 32位加密:GetMd5Str32
/// <summary>
/// 32位MD5加密
/// </summary>
/// <param name="strSource">待加密字串</param>
/// <returns>加密後的字串</returns>
public static string GetMd5Str32(string strSource)
{
byte[] bytes = Encoding.ASCII.GetBytes(strSource);
byte[] hashValue = ((System.Security.Cryptography.HashAlgorithm)System.Security.Cryptography.CryptoConfig.CreateFromName("MD5")).ComputeHash(bytes);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 16; i++)
{
sb.Append(hashValue[i].ToString("x2"));
}
return sb.ToString().ToUpper();
}
#endregion
#region 核對md5編碼是否一致:CheckMd5String()
/// <summary>
/// 核對md5編碼是否一致
/// </summary>
/// <param name="ConvertString"></param>
/// <returns>如果一致返回true,否則返回false</returns>
///
public static bool CheckMd5String(string str1, string str2)
{
string md5String = str1; //需要驗證的字元串
string md5DbString = str2; //需要核對的32位md5編碼
int result = string.Compare(md5.Program.GetMd5Str32(str1), md5DbString, true);
if (result == 0)
{
return true;
}
else
{
return false;
}
}
#endregion
}
}
修改「UserControl1.Designer.cs」中的命名空間為「md5」,方法為「Program」,即可生成dll文件。
在...\bin\Debug文件假下,可以找到相應的dll文件。
二、部署dll流程:
首先把dll文件放到應用程序...\bin\Debug\下;
然後在解決方案中添加引用:右鍵滑鼠-->添加引用-->瀏覽-->選擇dll放置路徑後點擊「確定」。
注意:要在應用文件頭處使用using md5;命令。
測試應用程序代碼,如下:Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using md5;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string str1 = textBox1.Text.ToString();
string md5String = textBox2.Text.ToString();
textBox3.Text = md5.Program.GetMd5Str32(str1);
textBox4.Text = md5.Program.CheckMd5String(str1, md5String).ToString();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
Ⅸ sql server2012 jdbc如何連接資料庫
步驟分為3部:
1.通過sql server 配置管理器配置1433埠
2.將sqljdbc41.jar類庫添加到對應的工程中
3.在java程序中連接資料庫
步驟1:打開sql server 配置管理器,點擊TCP/IP右鍵,選擇啟用。將禁用的TCP/IP協議打開。
然後重啟sql server(mssqlserver)服務,使得tcp/ip協議生效。
步驟2:到microsoft官網下載sqljdbc41.jar類庫。http://www.microsoft.com/zh-CN/download/details.aspx?id=11774
將下載的壓縮包解壓,找到sqljdbc41.jar類庫即可。
然後進入eclipse界面,找到的當前工程文件,點擊右鍵,選中properties->Libraries->add external jars->找到我們剛剛下載到的sqljdbc41.jar類庫,添加即可。
步驟3:
import java.sql.*;
public class test3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
PreparedStatement ps=null; //(這里也可以使用statement,視情況而定)
Connection ct=null;
ResultSet rs=null;
try {
//1.載入驅動
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url="jdbc:sqlserver://localhost:1433;databaseName=test1";
String user="sa";//sa超級管理員
String password="654321";//密碼
//2.連接
ct=DriverManager.getConnection( url,user,password);
//3.創建發送端
pstmt = conn.prepareStatement("INSERT INTO staff(name, age) VALUES (?, ?)");
//通過PreparedStatement對象里的set方法去設置插入的具體數值
pstmt.setString(1, newen);
pstmt.setInt(2, 25);
pstmt.executeUpdate();
//插入成功提示
System.out.println("成功插入一條數據記錄!");
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}finally{
//關閉資源
try {
if(rs!=null){
rs.close();
}
if(ps!=null){
ps.close();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
jdbc連接資料庫OK!!!
Ⅹ c/c++怎麼連接資料庫,並執行SQL語句
C++連接SQL資料庫第一步 系統配置
1.設置SQLSERVER伺服器為SQL登錄方式,並且系統安全性中的sa用戶要設置登錄功能為「啟用」,還有必須要有密碼。
2.需要在ODBC中進行數據源配置,數據源選\」SQL SERVER」,登錄方式使用「使用輸入用戶登錄ID和密碼的SQL SERVER驗證」,並填寫登錄名(sa)和密碼,注意一點,密碼不能為空,這就意味著你的sa用戶必須得有密碼。否則無法通過系統本身的安全策略。測試通過就完成了配置。
C++連接SQL資料庫第二步 C++與SQL連接初始化
1.在你所建立的C++項目中的stdafx.h頭文件中引入ADO
具體代碼如下
#import 「c:\Program Files\Common Files\System\ado\msado15.dll」
no_namespace rename(」EOF」, 「adoEOF」) rename(」BOF」, 「adoBOF」)
2.定義_ConnectionPtr變數後調用Connection對象的Open方法建立與伺服器的連接。
數據類型_ConnectionPtr實際上是由類模板_com_ptr_t得到的一個具體的實例類。_ConnectionPtr類封裝了Connection對象的Idispatch介面指針及其一些必要的操作。可以通過這個指針操縱Connection對象。
例如連接SQLServer資料庫,代碼如下:
//連接到MS SQL Server
//初始化指針
_ConnectionPtr pMyConnect = NULL;
HRESULT hr = pMyConnect.CreateInstance(__uuidof(Connection));
if (FAILED(hr))
return;
//初始化鏈接參數
_bstr_t strConnect = 「Provider=SQLOLEDB;
Server=hch;
Database=mytest;
uid=sa; pwd=sa;」; //Database指你系統中的資料庫
//執行連接
try
{
// Open方法連接字串必須四BSTR或者_bstr_t類型
pMyConnect->Open(strConnect, 「」, 「」, NULL);
}
catch(_com_error &e)
{
MessageBox(e.Description(), 「警告」, MB_OK|MB_ICONINFORMATION);
}//發生鏈接錯誤
C++連接SQL資料庫第三步 簡單的數據連接
//定義_RecordsetPtr變數,調用它Recordset對象的Open,即可打開一個數據集
//初始化過程 以下是個實例
_RecordsetPtr pRecordset;
if (FAILED(pRecordset.CreateInstance(__uuidof(Recordset))))
{
return;
}
//執行操作
try
{
pRecordset->Open(_variant_t(」userinfo」),
_variant_t((IDispatch*)pMyConnect),
adOpenKeyset, adLockOptimistic, adCmdTable);
}
catch (_com_error &e)
{
MessageBox(」無法打開userinfo表\」, 「系統提示」,
MB_OK|MB_ICONINFORMATION);
}
C++連接SQL資料庫第四步 執行SQL語句
這里是關鍵,我認為只要你懂點SQL語句那麼一切都會方便許多比用上面的方法簡單,更有效率點。
首先
m_pConnection.CreateInstance(_uuidof(Connection));
//初始化Connection指針
m_pRecordset.CreateInstance(__uuidof(Recordset));
//初始化Recordset指針
CString strSql=」select * from tb_goods」;//具體執行的SQL語句
m_pRecordset=m_pConnection->Execute(_bstr_t(strSql),
NULL, adCmdText);//將查詢數據導入m_pRecordset數據容器
至此 你的SQL語句已經執行完成了m_pRecordset內的數據就是你執行的結果。
取得記錄:
while(!m_pRecordset->adoEOF)//遍歷並讀取name列的記錄並輸出
{
CString temp = (TCHAR *)(_bstr_t)m_pRecordset->GetFields()->GetItem
(」name」)->Value;
AfxMessageBox(temp);
pRecordset->MoveNext();
}
插入記錄
//記得初始化指針再執行以下操作
CString strsql;
strsql.Format(」insert into tb_goods(no,name, price)
values(』%d』,'%s』, %d)」,m_intNo,m_strName,m_intPrice);
m_pRecordset=m_pConnection->
Execute(_bstr_t(strsql),NULL,adCmdText);
修改記錄
CString strsql;
strsql.Format(」update tb_goods set name=』%s』 ,
price=%d where no=%d 「,m_strName,m_intPrice,m_intNo);
m_pRecordset=m_pConnection->Execute(_bstr_t(strsql),NULL,adCmdText);
刪除記錄
CString strsql;
strsql.Format(」delete from tb_goodswhere no= 『%d』 「,m_intNo);
m_pRecordset=m_pConnection->Execute(_bstr_t(strsql),NULL,adCmdText)