Can't connect to SQL database RRS feed

  • Question

  • I am doing simple Console Application, trying to connect to database and then to print records... whatever...
    I am failing to connect to database.

    I am sure my code is correct, and my connection string is right. I copied it from "Server Explorer" properties where I am successfully seeing all the tables and fields.
    I was googling this question and I figured it's about granting permission to my app to access sql server? Microsoft is suggesting to use permview.exe, but they for some reason think we all know where it is an how to use it. I couldn't find it on my machine. And, then... why would I need to set permissions if I am providing login and pass in my connection string? This doesn't have any sense to me. I have VS 2005 installed.

    Please somebody help me with this.

    here is my code:

    Code Block

    string ConnectionString = @"Network Library=DBMSSOCN;Data Source=servername;Initial Catalog=dbtest;User ID=xxx;Password=xxx;";
    SqlConnection thisConnection = new SqlConnection(ConnectionString);
    thisConnection.Open();               //it fails here


    This is the error message:
    Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
    Monday, December 17, 2007 7:14 PM


  • Is the application deployed to a network drive? If so, it's in a zone that doesn't grant that permission. Either way, try this:

    1. In Solution explorer right-click the project and select properties
    2. Click Security tab
    3. Check 'Enable ClickOne Security settings'.
    4. Select 'This is a full trust application' or appropriate security settings.
    5. Recompile and run.
    Monday, December 17, 2007 8:57 PM