views:

100

answers:

6

I have a sql server on a dedicated machine, running SQL 2008. I have the IP of the box, a database setup on it.

I've built a small script that just does a connection test, and when I run it, I get the following error.

Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

I've been told by the admin that SQL remote access has been granted for my IP address.

Anybody know what's wrong?

A: 
  • Is your connection string correct?

Are you using a connection string similar to show here connectionstrings.com

  • Are your username and password correct?

username=xxx;pwd=xxx;

  • Are you using a trusted or non trusted connection?

*Trusted_Connection=True;*

  • Can you ping the server in question?
CResults
My connection string is of the form connString = "Data Source=ipAddressHere; Initial Catalog=dbName;User ID=user;Password=pass;"SqlConnection conn = new SqlConnection();conn.ConnectionString = connString;conn.Open();The database is accessible, the username and password is correct.What do you mean by 'definitely connecting by IP?How do you tell if its a trusted connection or not?
Matt
Can you explain the Tusted_Connection=Truel; bit... Where does that go?
Matt
A trusted connection is where the db server knows who you are by your windows login or group (rather than username/password). Definitely connecting by IP - is the server set up to accept connections by IP rather than named pipes only.
CResults
A: 

Might need a bit more info about your environment.

Active Directory? Make sure that SQL client is running under a domain account and that it is in the same domain as users trying to access it.

Let us know if not AD or if that doesn't work, and we'll keep trying from there.

(Also, I'm not sure about "remote access has been granted for my IP address." You need actual login credentials.)

Jay
A: 

Has the SQL Server been configured to allow remote connections yet using the appropriate protocol - I'd presume TCP/IP. If it's a fresh install this step may have been missed.

After confirming the basic config the steps CResults has listed should get you there.

Chris W
A: 

To force TCP/IP (if your client defaults to somthing else), try adding this to your connectionstring ";Network Library=dbmssocn", so that it looks something like this:

Data Source=ipAddressHere;Initial Catalog=dbName;User Id=user;Password=pass;Network Library=dbmssocn

or

Data Source=tcp:ipAddressHere,1433;Initial Catalog=dbName;User Id=user;Password=pass
Fredrik Johansson
A: 

To help rule out any sys-admin type problems I would recommend connecting using SQL Management studio on your client machine. If this isn't available use the Visual Studio Server Explorer to initiate a connection.

Assuming this connects then verify you can run whichever SQL command you are using in your test.

Joel Mansford
A: 

It turned out to be a .NET security issue.. Solved now..

Matt