zoukankan      html  css  js  c++  java
  • dac mssql server

    unit Unit1;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, FireDAC.Stan.Intf, FireDAC.Stan.Option,
      FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf,
      FireDAC.DApt.Intf, FireDAC.Stan.Async, FireDAC.DApt, FireDAC.UI.Intf,
      FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Phys, FireDAC.VCLUI.Wait,
      FireDAC.Phys.MSSQLDef, FireDAC.Phys.ODBCBase, FireDAC.Phys.MSSQL,
      FireDAC.Comp.UI, Data.DB, FireDAC.Comp.Client, FireDAC.Comp.DataSet,
      Data.Win.ADODB, Vcl.Grids, Vcl.DBGrids, Vcl.StdCtrls;
    
    type
      TForm1 = class(TForm)
        ds1: TDataSource;
        dbgrd1: TDBGrid;
        FDQuery1: TFDQuery;
        con1: TFDConnection;
        FDGUIxWaitCursor1: TFDGUIxWaitCursor;
        FDPhysMSSQLDriverLink1: TFDPhysMSSQLDriverLink;
        btn1: TButton;
        btn2: TButton;
        procedure btn1Click(Sender: TObject);
        procedure btn2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    {
    Provider=SQLOLEDB.1;Password=123;Persist Security Info=True;
    User ID=sa;Initial Catalog=HY_STD;Data Source=.
    }
    procedure TForm1.btn1Click(Sender: TObject);
    var
      oParams: TStrings;
    begin
      oParams := TStringList.Create;
      oParams.Add('Server=127.0.0.1');
      oParams.Add('Database=HY_STD');
      oParams.Add('OSAuthent=Yes');
      FDManager.AddConnectionDef('MSSQL_Connection', 'MSSQL', oParams);
      con1.ConnectionDefName := 'MSSQL_Connection';
    
      con1.Connected := True;
      FDQuery1.Open('select * from tb_userInfo');
    end;
    
    //sqlserver网络配置-> sqlserver的协议->tcp/ip 启用
    //(默认是不启用的,若连接的数据库是mssql,则必须手工去启用,
    //否则连接不上。)
    
    procedure TForm1.btn2Click(Sender: TObject);
    begin
      with con1.Params do
      begin
        Add('DriverID=MSSQL');
        Add('Database=HY_STD');
        Add('User_Name=sa');
        Add('Password=123');
        Add('Address=127.0.0.1');
        Add('CharacterSet=UTF8'); // 否则中文乱码
      end;
      con1.Connected := True;
      FDQuery1.Open('select * from tb_userInfo');
    end;
    
    
    end.
    书搞进脑袋 创新 创造; 积极
  • 相关阅读:
    再次写给我们这些浮躁的程序员
    SecureCRT的安装与破解,详细过程
    【SecureCRT】SecureCRT 护眼配色
    [Shell]常用语法
    [mysql]查看mysql执行情况的几种方法
    [vbs]脚本启动
    js 获取 网页屏幕高度 窗口高度 元素高度 滚动高度
    angular2 ng build --prod 报错:Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory'
    npm install warning: no description; no repository field
    vscode: Visual Studio Code 常用快捷键
  • 原文地址:https://www.cnblogs.com/tobetterlife/p/12171174.html
Copyright © 2011-2022 走看看