Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Cetin Basoz
  Where is Cetin Basoz?
 Izmir
 Turkey
 Cetin Basoz
 To: Ahsan Rana
  Where is Ahsan Rana?
 Lahore
 Pakistan
 Ahsan Rana
 Tags
Subject: RE: Connection String from Sql Server 2005
Thread ID: 365271 Message ID: 365300 # Views: 39 # Ratings: 5
Version: Visual FoxPro 9 SP2 Category: Databases, Tables and SQL Server
Date: Monday, December 24, 2012 3:24:09 AM         
   


> >
> > --
> > Correct for what? for who?
> > http://www.connectionstrings.com/Articles/Show/all-sql-server-connection-string-keywords
> >
> >
> > Michel L
>
> The following string is not working and showing error
>
> cStr = "Driver={Sql Server};Server=.;Database=Malik13;Trusted_Connection=Yes;"
> mConn=SqlStringConnect(cStr)
>
>
>
>
> Rgds:
> Ahsan Rana

Ahsan,
You need to know the server's location, instance name if any and the database name.
First try connecting without a database name. If you connect then you would know that you were typing database name wrong and could query all the database names from the connection.

Now look at the parts:

Driver={Sql Server}

This is old SQL server 2000 client driver. Do not use it. Use a newer one (2005 at least for 2005 server):

Driver={Sql Native Client}

Trusted_connection=yes

should be OK as long as you are trying to connect to a local instance and you are an admin in your computer.

server=.

This means you are referring to "default instance" on "local" machine. While this was common for SQL2000, SQL 2005 and later support and usually install with an instance name, for example SQL express by default is installed with "SQLExpress" as the instance name. You refer to that install as (again with . to mean local):

server=.\SQLExpress

This is the piece where you go wrong mostly.

To find that out easiest would be to use SSMS (SQL Server Management Studio) which I think already installed on your computer. Run that. A connection dialog comes up and you can connect with it? If so check what does it say for "Server name". If it says:

Yourcomputername

only then it is:

server=.

If it says:

yourcomputername\SQLExpress

then it is:

.\SQLExpress

vice versa. Also pay attention to if authentication is "windows authentication" (trusted_connection=yes) or not (if not then you need to add same username and pwd to your connection string:

Driver={Sql Native Client};server=.\SQLExpress;uid=username;pwd=password;database=yourDbName

(windows authentication is the preferred one).

You can also use SQL server configuration manager (from start menu) to find out the instance name. Under sql server services check for if the service is running and what the name is for the running instance (check for the name in parentheses - MSSQLSERVER for default instance . and SQLEXPRESS for .\SQLExpress etc).

HTH



Cetin Basoz

.Net has got better.Think about moving - check my blog:
My Blog
Blog (mirror) - sounds to be down


Support Wikipedia

ENTIRE THREAD

Connection String from Sql Server 2005 Posted by Ahsan Rana @ 12/23/2012 4:44:09 PM
RE: Connection String from Sql Server 2005 Posted by Michel Levy @ 12/23/2012 4:46:53 PM
RE: Connection String from Sql Server 2005 Posted by Ahsan Rana @ 12/23/2012 5:02:58 PM
RE: Connection String from Sql Server 2005 Posted by David Mustakim @ 12/23/2012 6:13:00 PM
RE: Connection String from Sql Server 2005 Posted by Ahsan Rana @ 12/24/2012 3:21:35 AM
RE: Connection String from Sql Server 2005 Posted by Michel Levy @ 12/23/2012 6:15:58 PM
RE: Connection String from Sql Server 2005 Posted by Ahsan Rana @ 12/24/2012 3:11:58 AM
RE: Connection String from Sql Server 2005 Posted by Anders Altberg @ 12/23/2012 6:30:02 PM
RE: Connection String from Sql Server 2005 Posted by Cetin Basoz @ 12/24/2012 2:57:03 AM
RE: Connection String from Sql Server 2005 Posted by Cetin Basoz @ 12/24/2012 3:24:09 AM
RE: Connection String from Sql Server 2005 Posted by Ahsan Rana @ 12/24/2012 4:31:45 AM