Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Reading data from SQL Server tables

Marilyn_Gambone
Beginner
1,771 Views
Hi,

How do I read data from a SQL Server table. I just installed Intel Visual Fortran Composer XE 2011.
0 Kudos
7 Replies
Anonymous66
Valued Contributor I
1,771 Views
Hello Marilyn,

On Windows you can use the COM object interface to communicate with the SQL Server. See "Key Features > Fortran Language Extensions > Intel Fortran Language Extensions > Using the Intel Fortran COM Server" in the Intel Visual Fortran Composer XE for Windows* documentation for more information about using the COM interface in Fortran.
0 Kudos
Arjen_Markus
Honored Contributor II
1,771 Views
Alternatively, you might be able to use the ODBC method - see the ODBC module in my Flibs
project - http://flibs.sf.org.

Regards,

Arjen
0 Kudos
DavidWhite
Valued Contributor II
1,771 Views
Should be on sf.net not sf.org
0 Kudos
Arjen_Markus
Honored Contributor II
1,771 Views
Thanks, David, for correcting this - I seem to be eternally remembering it the wrong way.

Regards,

Arjen
0 Kudos
Marilyn_Gambone
Beginner
1,771 Views
Hi,

Thank you for the reply. This is my first ever venture into Fortran world (yeah, we touched on it in college, but it was only to say that there is a language called Fortran). I'm a C# developer and haven't been exposed to other languages (except ESRI's ArcObjects for GIS applications).

My problem is we have a soil and water modeling software written in Fortran. It has several routines that read from a bunch of text files. It came to a point that it's difficult to maintain the text files so we moved them to a SQL Server database. But we really can't "throw away" the Fortran codes because it's been in our research center that long and quite difficult to modify them. So we we're thinking of modifying only the portions that reads in/writes out data (instead of reading/writing to text files, make the routines read/write to database tables).

I've seen the FLIBS from the link. I didn't see a download portion. I'm not sure how I can use them. Attached is a sample routine from our source codes. How would I modify this, using the FLIBS, to read from a SQL Server database named "SsurgoSwatUsDb" and a table named "TX001_Soil" (instead of a text file), using exactly the same column names?

Appreaciate any suggestions.
0 Kudos
SergeyKostrov
Valued Contributor II
1,771 Views
Hi Marilyn,

Quoting Marilyn Gambone
...It has several routines that read from a bunch of text files. It came to a point that it's difficult to maintain the text files so we moved them to a SQL Server database. But we really can't "throw away" the Fortran codes because it's been in our research center that long and quite difficult to modify them...

I recommend you to consider ODBC ( high level ) accessinstead of SQL DMO ( low level ) access.

Even if ODBC APIs are slower than SQL DMO APIs it will easily take care of all the rest problems, like
compatibility. ODBC isone of the most universal APIsandallows to work with different data sources for
atxt-file(s) or a relational database tables.

Best regards,
Sergey
0 Kudos
joerg_kuthe
Novice
1,771 Views
Maybe ForDBC helps to get your job done.

It is a library containing all the Fortran functions to access any database for which an ODBC driver is available (like MS/SQL) under Windows. See:

http://www.qtsoftware.de/oxShop/en/Libraries-Tools/for-Databases-Tables/ForDBC-Fortran-95-database-connection-via-ODBC.html

Kind regards,

Joerg Kuthe
www.qtsoftware.com

0 Kudos
Reply