By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,136 Members | 2,145 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,136 IT Pros & Developers. It's quick & easy.

Can't connect to SQL Server

P: n/a
Using this code:

Dim oConn As SqlClient.SqlConnection
oConn = New SqlClient.SqlConnection()
oConn.ConnectionString = "..." 'Connection string I got via an .udl file
oConn.Open()

I get an error here:

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

I tried to connect to an other database I normaly can connect to in an other
application: same error
I copied the connection string from an application that can connect to the
database and tried to connect: same error
I moved my database local and tried to connect: same error.


--
RW
Jul 18 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Wed, 18 Jul 2007 10:10:01 +0200, RW <RW@discussions.microsoft.comwrote:
Using this code:

Dim oConn As SqlClient.SqlConnection
oConn = New SqlClient.SqlConnection()
oConn.ConnectionString = "..." 'Connection string I got via an .udl file
oConn.Open()

I get an error here:

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

I tried to connect to an other database I normaly can connect to in another
application: same error
I copied the connection string from an application that can connect tothe
database and tried to connect: same error
I moved my database local and tried to connect: same error.

It would really help if you provide as much information as you can in these cases. From what you have written, it would appear that the database (or at least the server) is healthy, yet your application is denied access to this specific database, or to all databases?

If you are using a login, verify that the login exists on the sql serverand has proper access. Verify that the server allows logins and not windows authentication only.

If you are accessing using a web application, verify the proper, you need to take the user account the web application is running under into account when using windows authentication.

If you are developing a webpart in sharepoint or similar, you may have trust considerations as well.

....

--
Happy coding!
Morten Wennevik [C# MVP]
Jul 18 '07 #2

P: n/a
Thanks Morton

In the meantime I found the solution for my problem.
It was a security problem. My application was located on a shared server.
I just needed to add that server to the trusted list with mscorcfg.msc.

see atrticle: http://msdn2.microsoft.com/en-us/lib...xc(vs.71).aspx
--
RW
"Morten Wennevik [C# MVP]" wrote:
On Wed, 18 Jul 2007 10:10:01 +0200, RW <RW@discussions.microsoft.comwrote:
Using this code:

Dim oConn As SqlClient.SqlConnection
oConn = New SqlClient.SqlConnection()
oConn.ConnectionString = "..." 'Connection string I got via an .udl file
oConn.Open()

I get an error here:

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

I tried to connect to an other database I normaly can connect to in an other
application: same error
I copied the connection string from an application that can connect to the
database and tried to connect: same error
I moved my database local and tried to connect: same error.



It would really help if you provide as much information as you can in these cases. From what you have written, it would appear that the database (or at least the server) is healthy, yet your application is denied access to this specific database, or to all databases?

If you are using a login, verify that the login exists on the sql server and has proper access. Verify that the server allows logins and not windows authentication only.

If you are accessing using a web application, verify the proper, you need to take the user account the web application is running under into account when using windows authentication.

If you are developing a webpart in sharepoint or similar, you may have trust considerations as well.

....

--
Happy coding!
Morten Wennevik [C# MVP]
Jul 18 '07 #3

P: n/a
I found the solution for my problem.
It was a security problem. My application was located on a shared server.
I just needed to add that server to the trusted list with mscorcfg.msc.

see atrticle: http://msdn2.microsoft.com/en-us/lib...xc(vs.71).aspx
--
RW
"RW" wrote:
Using this code:

Dim oConn As SqlClient.SqlConnection
oConn = New SqlClient.SqlConnection()
oConn.ConnectionString = "..." 'Connection string I got via an .udl file
oConn.Open()

I get an error here:

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

I tried to connect to an other database I normaly can connect to in an other
application: same error
I copied the connection string from an application that can connect to the
database and tried to connect: same error
I moved my database local and tried to connect: same error.


--
RW
Jul 18 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.