ASP.NET help

GiLtY

Golden Member
Sep 10, 2000
1,487
1
0
Hello, I need some help with ASP.NET (I'm stlll learning it, but want to start programming so I won't forgot what I already read). I haven't got to database accessing, but for this one particular test program that I am making I need to access a SQL Server 2000 database. The way that I want to access the database is through the SYSTEM DSN, which I have already set up (and it works too, using ASP 3.0). The code that I have for the connection string is:
connectionStr = "DSN=GiLtY_DB;UID=;PWD="
but when I try to make a new connection, using this:
Dim myConnection As SqlConnection
Dim connectionStr As String
myConnection = New SqlConnection(connectionStr)
I get an error from the compiler saying that: "Unknown Connection option in connection string: dsn"
Is the DSN word not a defined word? or it's been replaced with another phrase (I know some people use data source, but I don't know if that's the one for me.) Any help is appreciated!

 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
DSNs are part of ODBC, therefore you will need the ODBC .NET Managed Provider. The ODBC .NET Managed Provider will be included in Visual Studio .NET 2003.

If you still want to use the SQL Server Managed Provider, you'll need a new connection string. Which you need is contingent upon your requirements. Check ConnectionStrings.com for examples.
 

calpha

Golden Member
Mar 7, 2001
1,287
0
0
Man, moving to ADO.Net from ADo was extremely painful to me.

I Musta spent an entire day figuring out how to connect to an ODBC data source, and then I saw the ODBC Managed Connection Library, and was cursing myself for the following two days for that utter waste of time.

I still don't like .NET. Until there's a plethora of 64Bit OSes out there on the server and destkop side....which would eventually lead M$FT to release a 64Bit version of .NET, I'm staying put in 6.0.

I know .NEt is sposed to make replace COM (not including Interop if you want to run old com objects in a .NET environment).....with managed and self describing libraries (thus no dll-hell is the promise) but I say no. C++ is still fastert ebay...that's what they use.

AFter my data nightmare with .NET, I quickly went back to C++ 6.0 and VB 6.0- and have loved everyday since then.
 

GiLtY

Golden Member
Sep 10, 2000
1,487
1
0
Yeah, I can't say I love ASP.NET a lot for a variety of reasons, one of them being connecting to the ODBC driver. It never worked on the first try... I'm still trying to figure out what I did wrong. I love C++, and I actually took an introductory course for C++, but nothing as close to VC, just some basics.
 

calpha

Golden Member
Mar 7, 2001
1,287
0
0
When you're using .NET....you just have to remember that everything has changed.

What I would try first if you're using a SQL2k database is to see if you cann connect using the SqlConnection (native MSSQl library ) in .NET.

mySQLCon = new SqlConnection(Connection string)

if you can...then you know you have an error in yoru DB ODBC String.

Buidling your ODBC connection string is a royal PITA sometimes........if you look in the online help for ODBC....you get re-refernced in a circular link usually.....and there's nothing (at least when I was using .NET) that says this data source uses this ODBC connection string. Furhtermore....after I got it to work.....I also used a bound control and compared the connection strings.......they were vastly different.

Again, I fallback to one of my rules.
Never use the first version of software, or the first version of a car.

That being said.... I was genuinely impressed w/ the stability of the .NEt environment.....but I loathed having to relearn everything including the basic language precepts....including C# compared to C++
 

GiLtY

Golden Member
Sep 10, 2000
1,487
1
0
I need help again!

When I try to run the page, I got this error:

Unknown connection option in connection string: driver

I already installed the ODBC .NET Managed Provider, and here are my codes:

SQLstr = "SELECT * FROM Names ORDER BY LastName"
ConnString = "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\GiLtY\ASP.NET\database\GDB.mdb;Uid=;Pwd=;"

When I set up the database, I didn't impose a password on the database. So I left the last two parameters blank.
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
calpha, you're blowing things way out of proportion. A developer should always be prepared to learn more. It really can't get much easier than ADO.NET. Every facet of .NET is simplified, imo, to the extreme. .NET is an absolute pleasure to work with.

I never understood why some developers complained about change. It is part of being a developer.... assimilate or enjoy obsolescence.

Originally posted by: GiLtY
I need help again!

When I try to run the page, I got this error:

Unknown connection option in connection string: driver

I already installed the ODBC .NET Managed Provider, and here are my codes:

SQLstr = "SELECT * FROM Names ORDER BY LastName"
ConnString = "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\GiLtY\ASP.NET\database\GDB.mdb;Uid=;Pwd=;"

When I set up the database, I didn't impose a password on the database. So I left the last two parameters blank.

Post the code. You're probably not using the OdbcConnection. The driver attribute is only part of OdbConnection, not SqlConnection.

 

GiLtY

Golden Member
Sep 10, 2000
1,487
1
0
Do'h, I'm such a dumbass... I'm not familiar with the different types of connectionStrings. Here's what I have now (after correcting the misuse of connectionString):

Dim myConnection As SqlConnection
Dim SQLstr As String
Dim connectionStr As String

SQLstr = "SELECT * FROM Users"
connectionStr = "Data Source = GiLtY; Initial Catalog= GiLtY; User Id = sa; Password=;"
myCOnnection = New SqlConnection(connectionStr)


Now my problem is that the user name "sa" is not associated with the trusted SQL Server connection (I have no idea what that means.. shows how much of a n00b I am :(). A little about the way I set up my SQL Server 2000:

When I set up the server registration, I used my local computer name (GiLtY) as the server. When I was asked to put in an username/password, i put "sa" for username and left the password field blank. Also I run on Win2k Pro.

Appreciate any help for this n00b!
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Just use this as your connection string then:

Server=gilty;Database=gilty;Integrated Security=true
 

GiLtY

Golden Member
Sep 10, 2000
1,487
1
0
Still no go :(

Now the error is " Login Failed for user 'GiLtY/ASPNET' "

I wonder if the problems are related to my SQL Server installation, or my operating system :confused:
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Sorry, I wasn't paying attention to the fact that you're doing this in ASP.NET. It will try to connect to the SQL Server using the ASPNET account (as you can see) which by default won't have access to the SQL Server using Windows authentication. There are several ways you can do this, but it would be easiest just to go into Enterprise Manager, expand your Server, and expand Security. Then simply right-click and add a New Login using the ASPNET account.

The other is to simply use SQL Server auth as you have been. If you need more connection string examples see connectionstrings.com.

HTH
 

GiLtY

Golden Member
Sep 10, 2000
1,487
1
0
Yeah, I just went into the Enterprise Manager and added a password for the default username (sa), and it worked!

Thanks for the help, good to know that I can still depend on Anandtech for my programming problems :D