?
Solved

Connect to a MSSQL database

Posted on 2006-11-06
14
Medium Priority
?
255 Views
Last Modified: 2010-04-05
I'm a novis in database connections.

My problem is that I have a MSSql (Microsoft SQL) database I need connection to. How too get connected too the database that is on a server.
Is it ADO that is best suited for the task or is it somthing else? And it is an other database with the same name on the server witch is accessed with ODBC so I have too be certen it is not that one I get connetcted on.

And i'm not using .net.

I'm using Borland Developer Studio 2006 by the way.

0
Comment
Question by:liljen_80
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 7
14 Comments
 
LVL 21

Expert Comment

by:ziolko
ID: 17881051
yup, ADO is the fastest way, moreover both ADO and MSSQL are Microsoft's technologies so they wor very nice together:)

ziolko.
0
 

Author Comment

by:liljen_80
ID: 17881163
Oki, that was what I tought. But I dont get in anny conflicts with the other database witch my be accessed by ODBC?
I have been locking for a site on the internet with some explenation on how too use ADO but I cant find anny good one, someone knows anny site?
0
 
LVL 21

Expert Comment

by:ziolko
ID: 17881266
nope there shouldn't be any conflicts with ODBC
for samples of ADO go to: \Program Files\Borland\BDS\4.0\Demos\DelphiWin32\VCLWin32\ADO

ziolko.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:liljen_80
ID: 17889215
Yea it was an example there, but it was very complex.
Does sombody have a simple solution on how and get a list of the tabels and how too conect a ADOTable to a database.

0
 
LVL 21

Accepted Solution

by:
ziolko earned 200 total points
ID: 17890322
drop down TADOConnection set connection string to your server and then:
 ADOConnection1.Open('your user name', 'your pass')
 ADOConnection1.GetTableNames();

here's little example:

object Form1: TForm1
  Left = 326
  Top = 88
  Caption = 'Form1'
  ClientHeight = 606
  ClientWidth = 862
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 76
    Top = 436
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 0
    OnClick = Button1Click
  end
  object DBGrid1: TDBGrid
    Left = 248
    Top = 212
    Width = 489
    Height = 301
    DataSource = DataSource1
    TabOrder = 1
    TitleFont.Charset = DEFAULT_CHARSET
    TitleFont.Color = clWindowText
    TitleFont.Height = -11
    TitleFont.Name = 'Tahoma'
    TitleFont.Style = []
  end
  object ADOConnection1: TADOConnection
    Connected = True
    ConnectionString =
      'Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initi' +
      'al Catalog=sdb;Data Source=LUKASZZ\SQL2K'
    Provider = 'SQLOLEDB.1'
    Left = 84
    Top = 196
  end
  object ADOTable1: TADOTable
    Active = True
    Connection = ADOConnection1
    CursorType = ctStatic
    TableName = 'dat0001'
    Left = 84
    Top = 236
  end
  object DataSource1: TDataSource
    DataSet = ADOTable1
    Left = 172
    Top = 240
  end
end

ziolko.
0
 
LVL 21

Expert Comment

by:ziolko
ID: 17890335
You have to modify ConnectionString and TableName to your values

ziolko.
0
 

Author Comment

by:liljen_80
ID: 17896385
But how is it possible too make a list of the TableNames where the user my pick witch Table too show?
0
 
LVL 21

Expert Comment

by:ziolko
ID: 17896905
use ADOCOnnection.GetTableNames() display result for user when user selects table asign it's name to ADOTable.TableName and then set ADOTable.Active := True

ziolko.
0
 

Author Comment

by:liljen_80
ID: 17896937
I solved the last problem my self.

But I got a problem when I'm going into the database fore the first time. I get up that I have too write in the password and username. But it does not mather what i write, I get into the database no mater what I write.

This is the ConnectionString: Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=HET;Data Source=OLE\BERE
0
 
LVL 21

Expert Comment

by:ziolko
ID: 17897888
thats because You selected "Use Windows NT Integrated Security"  and therfore in connection to DB security context of logged on user (logged on to computer) is used instead of login/password You specify.

You can either set ADOCOnnection.LoginPrompt := False to use logged on user or remove >>Integrated Security=SSPI;<< from Your connection string (same as uncheck "Use Windows NT Integrated Security")

ziolko.
0
 

Author Comment

by:liljen_80
ID: 17905287
It worked with ADOCOnnection.LoginPrompt := False, thanks.

This is how I alter a table:
if ADOTable1.Locate('ID',45,[loCaseInsensitive]) then
begin
  ADOTable1.Edit;
  ADOTable1.FieldByName('ID').AsInteger := 65;
  ADOTable1.Refresh;
end;

But how too do this so that nobody other get access to alter this while I'm doing the change. Besause if it is done the way my code is it is generated an error, but I need it so that the last one dont get too do the altering and just continues.
0
 

Author Comment

by:liljen_80
ID: 17905296
The error message is:
Row can not bi located for updating. Some values may been changed since it was last read.
0
 
LVL 21

Expert Comment

by:ziolko
ID: 17905548
try ADOTable1.Post instead ADOTable1.Refresh;

ziolko.
0
 

Author Comment

by:liljen_80
ID: 17913174
I have some more problems with ADO database connection, I would appreciate if you would take a look at this problem
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_22054714.html

Regards
Jan
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question