GeorgeInKansas
GeorgeInKansas

Reputation: 51

ASP.NET Web Service Cannot Access SQL Server DB

I created a Web Service project in VS 2010. I can get the non SQL functions to work perfectly. But I cannot get a simple Sql Server DB connection to even open. The connect string works fine for other ASP.NET web sites I have created. I am currently just running it locally on my development box. But the other ASP.NET Web Sites work locally fine with the same connect string. My code is below. The return on the error catch is also below. I have search google and find nothing to assist me in fixing this issue. Any help would be gratly appreciated. Thanks!!

System.Security.SecurityException: Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) at System.Security.PermissionSet.Demand() at System.Data.Common.DbConnectionOptions.DemandPermission() at System.Data.SqlClient.SqlConnection.PermissionDemand() at System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection outerConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.SqlClient.SqlConnection.Open() at WebServiceTest.Service1.GetAccountName(String VID) The action that failed was: Demand The type of the first permission that failed was: System.Data.SqlClient.SqlClientPermission The Zone of the assembly that failed was: Intranet

 <WebMethod()> _
Public Function HelloWorld() As String
   Return "Hello World"
End Function

<WebMethod()> _
Public Function ThisIsATest() As String
    Return "This Is A Test"
End Function

<WebMethod()> _
Public Function GetAccountName(VID As String) As String
    Dim conn As New SqlConnection
    Dim myc As New SqlCommand
    Dim wk As String
    wk = ""

    conn.ConnectionString = "Data Source=xxxxxxxx;Initial Catalog=WORKT;Integrated Security=False;UID=readonly;PWD=readonly"
    Try
        conn.Open()
    Catch e As Exception
        wk = e.ToString
    End Try

    conn.Close()

    Return wk
End Function

Upvotes: 0

Views: 614

Answers (1)

GeorgeInKansas
GeorgeInKansas

Reputation: 51

For anyone else searching this issue, It ended up being a permission issue because my app was stored on a network share. Here is the web site that helped me fix it. I had to add the shared mapped drive to the ASP trusted folders.

http://msdn.microsoft.com/en-us/library/zdc263t0(v=vs.90).aspx

Upvotes: 1

Related Questions