Connecting Foxpro to SQL Server 2005

I am trying to connect to a SQL Server 2005 database Spain.mdf.  

I am using a variant of the code I am using for connection to Access tables:

lcmyfile = "c:\spain.mdf"
lnconnhandle = ;

Access works fine.   My Excel routine works file, SQL bombs.

Any ideas
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


SQLSTRINGCONNECT('Driver={SQL Server};;AttachDbFilename=c:\spain.mdf;Server=localhost;Database=spain;Trusted_connection=yes')

Are you using SQL Server or SQL Server Express.
fmoore0001Author Commented:

That got me further than I have did.  I got a login error, then I relogged, and got this error:

Connection Failed:
SQLState: 'S1000'
SQL Server Error: 0
[Microsoft][ODBC SQL Server Driver]Cannot generate SSPI context

Almost there!
Maybe you should change the zone to also include SQL Server Experts.

Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

I've never used AttachDbFilename=c:\spain.mdf in connection to SQL Server.

Following connection strings work for me:

SQLSTRINGCONNECT("Driver={SQL Server};database=spain;server=ComputerName\SQLServerInstanceName;uid=username;pwd=password")
SQLSTRINGCONNECT("Driver={SQL Server};database=spain;server=ComputerName\SQLServerInstanceName;trusted_connection=Yes")

You could also try to create DSN (in Control panel - Administrative Tools - ODBC data sources  or  Control panel - Additional Options - ODBC). DSN will allow to select available SQL server and test the connection before its first use, it will also allow to select the best connection and authentication methods.

If you create DSN then you may use SQLCONNECT() to establish the connection and select defined DSN from the dialog.

Other connection string examples are here:
Also some hints how to solve "Cannot generate SSPI context" error are here:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fmoore0001Author Commented:
Thanks for the help, guys.  I was able to get in.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.