Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't connect to SQL database

Status
Not open for further replies.

mrkan

Programmer
Oct 30, 2006
39
US
Need help:

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

There is some example here: basically they suggest to use "Server=ComputerName, PortNumber", but anyway, the whole thing doesn't work. (not first time dough...)

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:
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=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
 
I don't think you need to use "Network Library" if you are connecting via a server name.

Maybe something like this is what you need:

ConnectionStrings.com said:
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

Hope this helps,

Alex

[small]----signature below----[/small]
I'm pushing an elephant up the stairs

My Crummy Web Page
 
Thanks all...

I saved project to network shared drive. VS reported that it is unsecured location, but I ignored it. When I saved project locally everything was fine.

Now I wonder WHY it didn't work on shared drive? Anybody have idea?
 
it is because the application is not trusted from that drive by "YOUR" pc. If you want to run an application from a network drive you must inform caspol.exe on YOUR machine that you trust the application. NOTE: this will only work if the application has been built with a strong name key pair... Hope this helps.

Age is a consequence of experience
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top