473,785 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Connecting to SQL Server DB

Hi all,

I'm missing something, probably stupid, on connecting to a SQL Server
database from an aspx file. I haven't really done much w/ SQL Server and
suspect that it's a problem on that side. I've installed the SQL Server
developer edition locally and do have a pubs database.

The connection I'm attempting is the following:

SqlConnection objConnection =
new SqlConnection( "server=localho st;database=pub ;uid=sa;pwd=adm in" );

try
{
// Open the connection.
objConnection.O pen();
/*snip*/
}
catch( Exception ex )
{
ErrorMessage.Te xt = ex.Message.ToSt ring();
}

The exception caught indicates (whether or not 'sa' is the uid I'm trying to
connect with):
Login failed for user 'sa'. Reason: Not associated with a trusted SQL Server
connection. (w/Windows-only Authentication) or
Login failed for user 'sa'. (Windows and SQL Server Authentication)

I have been able to create a connection through VFP (though using ODBC).
The connection string it creates is:
DSN=SQLServer1; UID=sa;PWD=admi n;APP=Microsoft Visual FoxPro;WSID=J2K , which
indicates to me that the sa/admin login is correct (which is what Iset at
installation).

Any ideas?

TIA,

John
Nov 18 '05
14 1868
I don't mind cross-posting so much as multi-posting. However this probably
belonged in one of the following sets:

[microsoft.publi c.dotnet.framew ork.adonet,
microsoft.publi c.sqlserver.con nect]

[microsoft.publi c.dotnet.framew ork.adonet,
microsoft.publi c.sqlserver.con nect]

[microsoft.publi c.sqlserver.con nect]

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"John Spiegel" <js******@YETAN OTHERSPAMHATERc-comld.com> wrote in message
news:#R******** ******@TK2MSFTN GP09.phx.gbl...
Hey Eric,

Aside from the connection issue...
Cross-posting is bad.
I've seen this dozens of times (part of why 90+% of the time I don't do

it). But I've never really understood what the problem is--particularly in a case where there are multiple technologies thrown in the mix. Is it a resource
issue for the newserver or confusion/clutter issue for the readers? Just
trying to understand.

Sorry for being bad,

John

Nov 18 '05 #11
You know you're right. It wasn't _that_ bad. Perhaps I just jumped on
something I don't like to see. One of the problems with x-posting is
readers who perhaps are not subscribed to the other groups might not see all
of replies. Likewise, when you are searching on a problem, you might
believe you're seeing incomplete threads hence a solution to an issue was
never found, however the thread could have just continued elsewhere.

Eric
"John Spiegel" <js******@YETAN OTHERSPAMHATERc-comld.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hey Eric,

Aside from the connection issue...
Cross-posting is bad.
I've seen this dozens of times (part of why 90+% of the time I don't do

it). But I've never really understood what the problem is--particularly in a case where there are multiple technologies thrown in the mix. Is it a resource
issue for the newserver or confusion/clutter issue for the readers? Just
trying to understand.

Sorry for being bad,

John

Nov 18 '05 #12
> something I don't like to see. One of the problems with x-posting is
readers who perhaps are not subscribed to the other groups might not see all of replies.


I bet this is rare. Usually, cross-posted groups are dropped when a user
finds that one or more of the groups was off-topic. So, a user who
frequents the off-topic group but not the on-topic group, would be unlikely
to be interested in the thread if it went solely to off-topic groups they
don't subscribe to.

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
Nov 18 '05 #13
My thanks and apologies to all. In a "didn't see the forest through the
trees" kind of way, I eventually realized that the downloaded code I was
using was using the compiled version of codebehind file and not the
on-the-fly changes I was making in the .cs file. Sheesh!

Thanks again for getting involved (and I learned some stuff in the process!)

- John

"John Spiegel" <js******@YETAN OTHERSPAMHATERc-comld.com> wrote in message
news:eX******** *****@TK2MSFTNG P11.phx.gbl...
Hi all,

I'm missing something, probably stupid, on connecting to a SQL Server
database from an aspx file. I haven't really done much w/ SQL Server and
suspect that it's a problem on that side. I've installed the SQL Server
developer edition locally and do have a pubs database.

The connection I'm attempting is the following:

SqlConnection objConnection =
new SqlConnection( "server=localho st;database=pub ;uid=sa;pwd=adm in" );
try
{
// Open the connection.
objConnection.O pen();
/*snip*/
}
catch( Exception ex )
{
ErrorMessage.Te xt = ex.Message.ToSt ring();
}

The exception caught indicates (whether or not 'sa' is the uid I'm trying to connect with):
Login failed for user 'sa'. Reason: Not associated with a trusted SQL Server connection. (w/Windows-only Authentication) or
Login failed for user 'sa'. (Windows and SQL Server Authentication)

I have been able to create a connection through VFP (though using ODBC).
The connection string it creates is:
DSN=SQLServer1; UID=sa;PWD=admi n;APP=Microsoft Visual FoxPro;WSID=J2K , which indicates to me that the sa/admin login is correct (which is what Iset at
installation).

Any ideas?

TIA,

John

Nov 18 '05 #14
It's true, the sqlConnection does not allow you to use an ODBC
connection so you'd either have to not use one, use the slower, less
optimized odbcConnection, OR... just read the ODBC settings from the
registry yourself. This is safe because if you're using a sqlConnection
then you're already commited to using just SQL server and so the
registry format should not change. Here's some sample code form
creating my connect string....

public DataConnection (string strUserName, string strPassword, string
strDSN)
{
Microsoft.Win32 .RegistryKey key =
Microsoft.Win32 .Registry.Local Machine.OpenSub Key("SOFTWARE\\ ODBC\\ODBC.I
NI\\" + strDSN);
if (key == null)
{
throw new Exception ("The specified ODBC datasource does not
exist.");
}
string databaseName = (string)key.Get Value ("Database") ;
string server = (string)key.Get Value ("Server");

m_strConnect = "user id=" + strUserName + ";password= " + strPassword
+ ";initial catalog=" + databaseName + ";data source=" + server;
}

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3639
by: Google Mike | last post by:
After a lot of thought and research, and playing with FreeTDS and InlineTDS, as well as various ODBC connections, I have determined that the fastest and cheapest way to get up and going with PHP on Linux, connecting to MS SQL Server, unless it was already pre-installed by your Linux installation, is to build your own multithreaded TCP socket server on Windows and connect to it through the socket API in PHP on Linux (if you have installed...
12
2793
by: Ann Marinas | last post by:
Hi all, I would like to ask for some help regarding separating the asp.net webserver and the sql server. I have created an asp.net application for a certain company. Initially, we installed both the iis and sql server in a single machine. Not too long ago, the machine had some hardware problems, and management has decided to purchase new servers, for both asp.net and sql server.
3
3004
by: Ann Marinas | last post by:
Hi there, I am currently developing an ASP.NET program that connects to a SQL Server 2000 database. I also have SQL Server 2005 Express installed on the same local machine. Prior to installing SQL Server 2005, my apps were working and is connecting flawlessly to a database on the SQL Server 2000. Now, whenever I connect to the same database with the 2005 version installed, I keep on getting this error:
0
2035
by: cj.snead | last post by:
Hello, I am having trouble connecting to a remote named instance of SQL Server via Pocket PC. I have had absolutely no luck connecting with VS 2005 (even to a default instance), so I wen't back to VS .NET 2003 (I had success doing this a while back). I am trying to connect to a named instance of SQL. This is where I think my problem is. My app errors out at the Connection.Open(); command. Here is my connection string:
3
2015
by: Vinod R.Shenoy | last post by:
Hi All, Came across a post wherin you had helped somebody with a similar problem and was wondering if you could help us out with it. Our problem is , We have a development SQL Server 2000 (running on Win2K SP4) machine that we want to run on a Windows 2003 server machine and access it via our internal LAN. We have opened the firewall to allow our applications
6
7778
by: Todd Brewer | last post by:
Windows Server 2000 ASP.NET 2.0 SQL Server 2000 (on a physically seperate server) I moved an ASP.NET 2.0 application from a development server to production, and am getting the following error: System.Data.SqlClient.SqlException: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not
10
15959
by: mairhtin o'feannag | last post by:
Hello, I'm having problems connecting to my new v9 db box. The pertinent information is below: DB2_db2inst1 60000/tcp DB2_db2inst1_1 60001/tcp DB2_db2inst1_2 60002/tcp DB2_db2inst1_END 60003/tcp
2
4965
by: samadams_2006 | last post by:
Hello, I have a problem that I'm hoping someone will be able to help me resolve. 1) I have a C# Web Site in which I connect to the database: "Install Microsoft SQL Server 2005 Express Edition" via the link on: http://msdn2.microsoft.com/en-us/express/bb410792.aspx
2
3045
by: orandov | last post by:
Hi, I am having a problem connecting my .net applications from the application server to the database server. When I run the application from my windows xp (sp2) box it works fine. When I try to connect via SQL Management Studio to the database server from the application server I get the same error. Here is the error:
0
2009
by: aboutjav.com | last post by:
Hi, I need some help. I am getting this error after I complete the asp.net register control and click on the continue button. It crashed when it tries to get it calls this Profile property ((string)(this.GetPropertyValue("Address1")));
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10148
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10091
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.