Connecting Tech Pros Worldwide Forums | Help | Site Map

VB.NET 2005 and SQL

Newbie
 
Join Date: Oct 2007
Posts: 11
#1: Oct 10 '07
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:
Expand|Select|Wrap|Line Numbers
  1. Public Function getdata() As Collection
  2.         Dim sqlcon As New SqlConnection("Data Source=DatabaseServer;Persist Security Info=True;Password=Pass0;User ID=Program;Initial Catalog=DBase1")
  3.  
  4.         sqlcon.Open() 'ERROR in this line.
  5.         Dim sqlcom As New SqlCommand
  6.         sqlcom.Connection = sqlcon
  7.         sqlcom.CommandType = CommandType.Text
  8.         sqlcom.CommandText = "SELECT example FROM(dbo.tbl_Test) WHERE (Active = 1)"
  9.         Dim Reader As SqlDataReader
  10.         Reader = sqlcom.ExecuteReader
  11.         Reader.Read()
  12.         Dim newCol As New Collection
  13.         While Reader.Read()
  14.             newCol.Add(Reader(0))
  15.         End While
  16.  
  17.         sqlcon.Close()
  18.         sqlcom.Connection = Nothing
  19.         Return newCol
  20.     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.

Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,137
#2: Oct 10 '07

re: VB.NET 2005 and SQL


Hi SniperDemon,

Does your SQL Database use SQL Server and Windows Authentication?
If so, have you tied to use Integrated Security?

Have you seen what msdn has to say about connection strings?

Thanks for formatting your question so clearly!

-Frinny
Newbie
 
Join Date: Oct 2007
Posts: 11
#3: Oct 11 '07

re: VB.NET 2005 and SQL


Thanks for your response.

I was able to figure it out..kinda, right before leaving work. I switched over to a console application and started testing my connection strings in the most basic way i could think of. It ended up working with minimal effort. I felt a little ridiculous after but at least it works now and is querying our database for the information.

My next task is a good efficient way to tell it to query and pull back an array of items so that i can re-use the code for multiple calls by putting in a function. Once it pulls back the array though it has to go through another loop to take the array and put it into a list box (not that hard) and put it into the excel sheets the program will be creating. I'm not really sure how hard the second part will be, it may not be as bad as i think it will.

If you have any ideas on that, it would also be greatly appreciated.
(I can't post more code until tomorrow seeing as i won't be back in the office till then)
Reply