all groups > dotnet general > april 2005 >
You're in the

dotnet general

group:

ADO DB Connection (SQL Server) via ASP.Net web app - help!!!!


ADO DB Connection (SQL Server) via ASP.Net web app - help!!!! kvrdev1
4/30/2005 5:41:02 PM
dotnet general:
I'm attempting to connect to a SQL Server DB, using ADO, from my new ASP.NET
web application. I can use the same connect string from within a VB.Net app
(windows app) just fine, but I cannot do it from within my web app... Here
is the error I am receiving:

Login failed for user '(null)'. Reason: Not associated with a trusted SQL
Server connection.

I am using windows authentication, which works just fine within my windows
app - I'm using the web server on my local machine... Here is my connect
string and code associated with this:

sDatabaseType = "SQL Server"
sServerName = "MyServer"
sDatabaseName = "MyDatabase"sConnectString = "DRIVER={SQL
Server};SERVER=" & sServerName & ";Trusted_connection=yes;DATABASE=" &
sDatabaseName & ";"
gdcDataConnection = New ADODB.Connection
gdcDataConnection.Open(sConnectString)

I would appreciate any help that you can provide!!!!!
Re: ADO DB Connection (SQL Server) via ASP.Net web app - help!!!! Dave
4/30/2005 11:59:49 PM
Use the System.Data.SqlClient.SqlConnection -- It is a strong-typed connection to an Sql Server instance. In the .NET world, you no
longer need the ADODB com object as you did with ASP. As a matter of fact, it is recommended to use the SqlClient namespace for use
with Sql Server instead of a generic ODBC (or OLE DB) connection.

// Create a connection object
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection();

// Connect to the server using windows authentication.
conn.ConnectionString = "Data Source=localhost; Initial Catalog=Northwind; Trusted_Connection=true;";

try
{
conn.Open();

// Todo: Use the connection...
/*
* Check out the other classes in the System.Data.SqlClient Namespace, such as:
* SqlDataAdapter
* SqlDataReader
* SqlCommand
* SqlException
/*
}
finally
{
conn.Close();
}


--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
[quoted text, click to view]

Re: ADO DB Connection (SQL Server) via ASP.Net web app - help!!!! Cor Ligthert
5/1/2005 12:00:00 AM
Kvrdev1.

Please do not multipost, I have now answered you in another newsgroup.

Crossposting is not any problem in the dotNet newsgroups. (Sending one
message to more relevant newsgroups in one time)

Cor

AddThis Social Bookmark Button