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 / May 2006

Tip: Looking for answers? Try searching our database.

Help - Problem Connecting to SQL Server ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Josh Grameson - 10 May 2006 20:06 GMT
I am having a problem with this code when trying to connect to SQL Server.

At home it works, at work there are prolbems.

Home computer is a stand alone computer runninw Window XP and SQL Server
2000.

Work computer is a network made up of:

Novell server

MSSQL Server 2000

Citrix Server

This code works when I run a copy of the program that is on the Citrix or
SQL Server drive, but if run from a Novel drive (no matter which computer I’m
running it from) it fails

This is the error that I get:

Application attempted to perform an operation not allowed by the security
policy. To grand this application the required permission, contact your
system administrator, or use the Microsoft .NET Framework Configuration too.

Request for the permission of type

‘System.Data.SqlClient.SqlClientPermission.System.Data,

Dim c As String = "Data Source=SQL;Initial Catalog=AhavaOrder;Integrated
Security=True"

Dim conn As New SqlConnection(c)

Dim cmd As SqlCommand = New SqlCommand("select * from tblItem", conn)

cmd.CommandType = CommandType.Text

cmd.Connection.Open()

Dim reader As SqlDataReader =
cmd.ExecuteReader(CommandBehavior.CloseConnection)

reader.Read()

MsgBox(reader.Item(0))
Jim in Arizona - 10 May 2006 21:49 GMT
> Dim c As String = "Data Source=SQL;Initial Catalog=AhavaOrder;Integrated
> Security=True"

Integrated security may be your issue. Try specifying an SQL
username/password that has permissions for the database in which you're
trying to connect.

An example:

Dim c As String = "server=SQL;uid=sa;pwd=pa$$w0rd;database=MyDatabase"
Josh Grameson - 10 May 2006 23:26 GMT
I there is something wrong with the Connection string as you have it here,
cause the following code which was change to use it does not work even on my
stand alone pc. (btw, i set up a login for user "ar" and pw of "xx".

Dim c As String = "server=SQL;uid=ar;pwd=xx;database=AhavaOrder"

MsgBox("using as connection: " & c)

Dim conn As New SqlConnection(c)

Dim cmd As SqlCommand = New SqlCommand("select * from tblItem", conn)

cmd.CommandType = CommandType.Text

cmd.Connection.Open()

Dim reader As SqlDataReader =
cmd.ExecuteReader(CommandBehavior.CloseConnection)

reader.Read()

MsgBox(reader.Item(0))

>> Dim c As String = "Data Source=SQL;Initial Catalog=AhavaOrder;Integrated
>> Security=True"
[quoted text clipped - 6 lines]
>
> Dim c As String = "server=SQL;uid=sa;pwd=pa$$w0rd;database=MyDatabase"
Josh Grameson - 10 May 2006 23:46 GMT
I'm Wrong!

This string actually does work, but only as much as the one that I was using
before with integrated security. Meaning this works on my home pc, and on
the non Novell drives on the network at work.

>I there is something wrong with the Connection string as you have it here,
>cause the following code which was change to use it does not work even on
[quoted text clipped - 29 lines]
>>
>> Dim c As String = "server=SQL;uid=sa;pwd=pa$$w0rd;database=MyDatabase"
Brendan Green - 10 May 2006 23:51 GMT
Is "uid" valid?  Or is it supposed to be "User Id"?

>I there is something wrong with the Connection string as you have it here,
>cause the following code which was change to use it does not work even on
[quoted text clipped - 29 lines]
>>
>> Dim c As String = "server=SQL;uid=sa;pwd=pa$$w0rd;database=MyDatabase"
Josh Grameson - 11 May 2006 02:03 GMT
It must be valid since it works (from home computer, etc.) Plus this was
given to me by Jim who it seems is an expert here.

> Is "uid" valid?  Or is it supposed to be "User Id"?
>
[quoted text clipped - 31 lines]
>>>
>>> Dim c As String = "server=SQL;uid=sa;pwd=pa$$w0rd;database=MyDatabase"
Jim in Arizona - 11 May 2006 17:12 GMT
Expert? no no! lol

I've been using that connection string for some time on several of my
web apps. I got it out of a book.

You can get specific connection strings from
http://www.connectionstrings.com which I have found somewhat useful in
the past.

As far as why you still can't connect, I'm not sure. Integrated security
uses windows trusts (active directory or local windows accounts) so if
you're using a computer that isn't windows or isn't part a windows
domain and you aren't logged onto that machine with a matching username
and password that the server has (ie: you're logged onto a workstation
as a local administrator with matching username/password
(administrator/mypassword) as the sql server computer (the local windows
account of administrator/mypassword, not the sql logon)).

As long as you're connecting strait to the sql service using sql
credentials, then it shouldn't matter where your connection is coming
from unless security on your sql computer is explicitly denying that
connection for some reason other than default reasons.

> It must be valid since it works (from home computer, etc.) Plus this was
> given to me by Jim who it seems is an expert here.
[quoted text clipped - 34 lines]
>>>>
>>>> Dim c As String = "server=SQL;uid=sa;pwd=pa$$w0rd;database=MyDatabase"

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.