Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / General / December 2005

Tip: Looking for answers? Try searching our database.

VS 2005 + SQL Server 2005 Connection problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ds_lewis@hotmail.com - 31 Dec 2005 09:03 GMT
Help!  I'm unable to connect to my SQL Server 2005 database from a C#
class.

This error message happens on the conn.Open() statement in my code:
Request for the permission of type
'System.Data.SqlClient.SqlClientPermission, System.Data,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
failed.

I have VS 2005 and Sql Server 2005 installed on my dev workstation.
I'm running the code in the debugger and I get the above error.  I have
tried a variety of connect strings - many more than listed here but
none worked so far.  All works fine from SQL Server 2005 Management
Studio.  I created a Integrated Services package, compiled and it runs
without a hitch.  VS can connect to the database fine.
TCPIP was enabled and I also enabled Named Pipes - no change.

Can anybody help me understand what I need to do to be able to connect
from code?

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

<snip>
                   cs = "Data Source=(local);Initial
Catalog=ScoreCard;Integrated Security=True";
                   cs = "Data Source=(local);Initial
Catalog=ScoreCard;Trusted_Connection=True";
                   cs = "Data Source=tcp:davel-vpc;Initial
Catalog=scorecard;User Id=someuser;Password=password;";
                   cs = "Data Source=myserver;Initial
Catalog=scorecard;User Id=someuser;Password=password";
<snip>

           DataTable dt = new DataTable();
           using ( SqlConnection conn = new SqlConnection(cs) )
Catalog=ScoreCard;Integrated Security=True"))
           using (SqlCommand cmd = new SqlCommand("GetCities",conn))
           {
               cmd.CommandText = "SELECT * FROM city";
               conn.Open();

               <snip>
               conn.Close();
           }

Targus.
ds_lewis@hotmail.com - 31 Dec 2005 21:00 GMT
Here is some additional information for the problem.

I get the same error if I try to connect to a SQL Server 2K database on
a second machine.
But I have VS 2003 installed on that second machine and I can connect
to the SQL Server 2005 database on the first machine without any
errors.
So I think it has to be a VS 2005 issue.

Again, Please help!

Targus

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.