|
-
May 21st, 2003, 08:45 PM
#1
Thread Starter
PowerPoster
Connecting to SQLSERVER with ADO.net
I've seen several examples on this board.. all of which were different and none of which actually seemed to work..
Does anyone have a good example using ADO.net to connect to SQL Server?
Thanks!
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
May 22nd, 2003, 09:15 AM
#2
Lively Member
This is how I do it,
This goes into the web.config file:
Code:
<appSettings>
<add key="dsnNt" value="data source=***.***.***.***;initial catalog=nnerensql;UID=******;PWD=*****"/>
</appSettings>
then I add these imports to my code behind page
Code:
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections.Specialized
then my query execution goes like this:
Code:
Dim conn As String
Dim appsetting As NameValueCollection = CType(HttpContext.Current.GetConfig("appSettings"), NameValueCollection)
conn = CStr(appsetting("dsnNT"))
Dim myConnection2 As SqlConnection = New SqlConnection(conn)
Dim dsLogin As SqlCommand = New SqlCommand("select something from the database", myConnection2)
Dim ds As SqlDataReader
myConnection2.Open()
ds = dsLogin.ExecuteReader()
while ds.read()
'do something
end while
ds.close
myconnection2.close
hope that helps
"Find all you need in your mind if you take the time" -DT
-
May 22nd, 2003, 10:02 AM
#3
What doesn't work about them?
The basics of the SQL connection string are the following:
NOTE: There is no provider section to the SQL connection string like in OLEDB
'Data Source'=This is either the SQL Server name if local or an IP address of the remote server, which may also need the port if not default
'Initial Catalog'=The database in the SQL Server you want to connect to
'Integrated Security=SSPI'=This uses the windows account to login to the SQL Server and can be replaced with a username (UID) and password (PWD) if not using Windows Authentication
'Persist Security Info'=I'm not really sure what this does or if it is required but I always seem to have it in my connection strings
Here is an example connection string:
Data Source=MHC2;Initial Catalog=MHC_NET;integrated security=SSPI;
VB Code:
'How to connect to a SQL Server
Dim cnn As New System.Data.SQLClient.SQLConnection("Data Source=MHC2;Initial Catalog=MHC_NET;integrated security=SSPI;")
cnn.Open
-
May 22nd, 2003, 09:17 PM
#4
Thread Starter
PowerPoster
OK thanks i'll give it a shot.
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|