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

G

Guest

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!!!!!
Thank you!-Valerie
 
D

Dave

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();
}
 
C

Cor Ligthert

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top