找到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)