SQL connection

SQL connection

Postby Jeff Barnes » Wed Jan 31, 2024 1:28 pm

So this is going to sound very simple to those of you who use sql but I've have never used sql so here goes....

All I need to do is:
-Connect to the SQL server
-Add a new record
-Add the data to the record (2 fields "Name" and "ID")
-Save and close

I've looked at some posts but I see different people doing things different ways and now I'm confused :shock:
I should also mention that I've been out of the programming game for a while and am a bit rusty.

Can anyone point me in the right direction?
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: SQL connection

Postby Jeff Barnes » Wed Jan 31, 2024 2:12 pm

Forgot to mention that it's a Microsoft SQL server I need to connect to.
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: SQL connection

Postby Otto » Wed Jan 31, 2024 3:23 pm

Hi, Jeff, nice to see you again. It seems like you haven't been here for a long time.
I've often wondered if you're still working on your program. Unfortunately,
I've shut down all my SQL servers and haven't done anything with them for a long time. But I'm happy to see you.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6312
Joined: Fri Oct 07, 2005 7:07 pm

Re: SQL connection

Postby Jeff Barnes » Wed Jan 31, 2024 3:40 pm

Hi Otto,

Nice to see you again too :)

I retired back in 2020 but still do a bit of programming here and there.
Glad to see your still going :)
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: SQL connection

Postby nageswaragunupudi » Wed Jan 31, 2024 8:28 pm

This is our recommendation:
Code: Select all  Expand view
function TestMsSql()

   local oCn, cSql, oRs
                                       // server      // db     // user   // pwd
   oCn := FW_OpenAdoConnection( "MSSQL,208.91.198.196,gnraore3_,fwhmsdemo,fwh@2000#", .t. )
   if oCn == nil
      ? "failed to connect"
   else
      cSql := "INSERT INTO [STATES] ( [CODE], [NAME] ) VALUES ( 'JB', 'Jeff Barnes' )"
      oCn:Execute( cSql )
      //
      // Now test
      oRs   := FW_OpenRecordSet( oCn, "SELECT * FROM [STATES]" )
      XBROWSER oRs
      oRs:Close()

      oCn:Close()
   endif

return nil
 

Image

You can test this program from your computer.
This program connects to a FWH's MsSql server in the cloud. This server is provided for testing by our users.
After testing this, you can use similar logic on your Server.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: SQL connection

Postby Jeff Barnes » Wed Jan 31, 2024 8:49 pm

Thank you sir. That works when I leave your sample alone.

When I add my connection info, it will not connect.
At least now I know it should work. Not sure why the connection isn't working on my end.
The big issue is me, I just don't know enough about the SQL Server.
Even if I create logins on the server (ie: User=Jeff), It will not let me connect unless I use "Windows Authentication". I think this is where my issue is.

I will keep on trying. :shock:
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: SQL connection

Postby Jeff Barnes » Sat Feb 03, 2024 1:13 am

Got it working. It was a setting in MS-SQL. I had to enable both Windows Authentication and SQL user authentication.

Thanks again for the help.
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 44 guests