Background:
Project Files are being store on a Network drive (I will refer to as G:)
SQL Database is located on another Network drive (I will refer to as H:)
I will refer to the SQL Database as
DBase1
Also I Will refer to the SQL Database Server as
DatabaseServer
The Final Program will be run from Workstations and querying the Database located on H:
For this Post the SQL Database will have an example user(
Program) and Password(
Pass0)
Currently we use Windows Authentication to connect to our Network drives.
Only IT Employees and the example user have access to the SQL Database.
Situation:
The Program is Erroring out inside the connection line.
I am unable to come up with a fix for connecting to the Database.
I have tried many different connection strings and have yet to have any success.
Error:
Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
The Code: - Public Function getdata() As Collection
-
Dim sqlcon As New SqlConnection("Data Source=DatabaseServer;Persist Security Info=True;Password=Pass0;User ID=Program;Initial Catalog=DBase1")
-
-
sqlcon.Open() 'ERROR in this line.
-
Dim sqlcom As New SqlCommand
-
sqlcom.Connection = sqlcon
-
sqlcom.CommandType = CommandType.Text
-
sqlcom.CommandText = "SELECT example FROM(dbo.tbl_Test) WHERE (Active = 1)"
-
Dim Reader As SqlDataReader
-
Reader = sqlcom.ExecuteReader
-
Reader.Read()
-
Dim newCol As New Collection
-
While Reader.Read()
-
newCol.Add(Reader(0))
-
End While
-
-
sqlcon.Close()
-
sqlcom.Connection = Nothing
-
Return newCol
-
End Function
Comments:
I know the problem is with the connection string but I am unsure as of how to go about fixing it.
I have already tried different types of strings but none worked. I was thinking the issue may have to do with the fact that not all users have access to the database but I do so it shouldn't matter.
Also maybe it could do with the fact that all users may not have access to that specific drive, but again I do so it shouldn't matter because i am debugging using my account.
It also could have to do with permissions and if that is the case how I go about giving it the required permissions to access what it needs to access.
Thank you in advance for any help you may give me. If you need more information that I have not provided just let me know. I will be checking this thread frequently.