我用ADO 连接数据库,程序如下:
procedure TForm1.Button1Click(Sender: TObject);
var str:string;
begin
str:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;
Initial Catalog=DBFANG;
Data Source=CW01';
ADOConnection1.connected:= false;
ADOConnection1.ConnectionString :=str;
ADOConnection1.connected:=true;
end;
我的计算机名字叫CW01, 我要连接的数据库的名字是DBFANG,
为什么我一运行到给STR赋值的时候就出错了呢?
procedure TForm1.Button1Click(Sender: TObject);
var str:string;
begin
str:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;
Initial Catalog=DBFANG;
Data Source=CW01';
ADOConnection1.connected:= false;
ADOConnection1.ConnectionString :=str;
ADOConnection1.connected:=true;
end;
我的计算机名字叫CW01, 我要连接的数据库的名字是DBFANG,
为什么我一运行到给STR赋值的时候就出错了呢?
解决方案 »
- 用delphi进行串口编程时 出现error reading comm device错误
- delphi 把excel导入到DBGrid再从dbgrid导入到sql
- 超级难提
- 历史上最经典智力题 ~~~历史上最经典智力题
- (菜鸟问题)求得了一个函数不知怎么返回出来,请大家再赐教一下.在线等
- 窗口问题
- 有关dll调显示窗口的问题(高分等待)
- 如何调用DLL中的窗口(我自己写的DLL)?
- 关于combobox的style属性的动态设置?
- 52分求购源程序!!怎样通过netbios获得远程主机机器名和以及工作组名称,以及操作系统等情况!
- 怎样才能知道局域网中服务器的IP地址呀?
- 好难得问题,100相送
GetComputerName();BOOL GetComputerName( LPTSTR lpBuffer, // address of name buffer
LPDWORD nSize // address of size of name buffer
);
var
wVersionRequested : WORD;
wsaData : TWSAData;
p : PHostEnt;
s : array[0..128] of char;
begin
wVersionRequested := MAKEWORD(1, 1);
WSAStartup(wVersionRequested, wsaData);
GetHostName(@s, 128);
p := GetHostByName(@s);
//ShowMessage(Format('Computer name is ''%s''.', [p^.h_Name]));
edit2.Text:=s;
end;
Initial Catalog=DBFANG;你的str是不是少点东西啊
应该加上datasource=127.0.0.1 //连接的服务器地址
Initial Catalog=DBFANG;//这个是连数据库的名字