Monday, February 20, 2012

ms sql

hi,
i would like to ask help from anybody here in the forum. i am using sql server 2000 installed in a different computer. in my computer i have microsoft visual studio .net (C# .net), windows 2000. i am trying to access the database dal. in my server explorer i add a connection. the connection is successful and i am now able to browse the tables and open it. however, i dragged from my server explorer the added connection to my form. Sqlconnection1 contains the connection and in my page load i added this code:


SqlConnection1.Open();
if (SqlConnection1.State == ConnectionState.Open)
{
Label1.Text = "SQL Connection is open";
}
else
{
Label1.Text = "SQL Connection is closed";
}


and it gave me this message:
Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details:System.Data.SqlClient.SqlException: SQL Server does not exist or access denied.
Line 51: SqlConnection1.Open();
Line 52: if (SqlConnection1.State == ConnectionState.Open)
what am i going to do? what's the possible cause of this problem? what's the possible solution?Hello Harrha19
An SqlConnection needs to have a connection string to connect to the database. The connection string depends a little on what the database is called, what the DNS name of the server / other computer is, what kind of authentication you use, etc.
When you use Windows authentication on your database then you need to make sure that the Windows account you use, has access to that database. A typical connection string using Windows authentication looks like: "Server=<servername>;Database=<database name>;Integrated Security=SSPI". A connection string for SQL Authentication looks like: "Server=<servername>;Database=<database name>;UID=<user name>;PWD=<password>"
If you did a "standard setup" of MSDE, then likely SQL Authentication will not be enabled. (You have to setup MSDE with the "Securitymode=SQL" parameter to do so) You can change this setting only with the Sql Enterprise Manager (server properties) Because of security reasons I recommend you to use Windows authentication.
Besides checking your connection string, check also if a Windows XP / Windows Server 2003 Firewall is not blocking traffic, but since you said you can browse the database from your IDE, this will likely not be the problem.
Best regards,

Jeroen Landheer|||

I have not change the setup Securitymode=SQL since i do not know how to do this. could you give the step by step instruction on how am i going to do it?

this is my connection string:


string MyConString2 = "Persist Security Info=False;User ID=sa;Initial Catalog=dals;Data Source=cerebrum;Packet Size=4096;Workstation ID=SOLARIS;";

SqlConnection myConnection = new SqlConnection(MyConString2);
myConnection.Open();

if (myConnection.State==ConnectionState.Open)
{
Label1.Text = "SQL Connection is open";
}
else
{
Label1.Text = "SQL Connection is closed";
}
myConnection.Close();


the same error. when i run the code.

SQL Server does not exist or access denied.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details:System.Data.SqlClient.SqlException: SQL Server does not exist or access denied.
Line 35:
Line 36: SqlConnection myConnection = new SqlConnection(MyConString2);
Line 37: myConnection.Open();



i really need your help.

|||When I take a look at your connection string you're using SQL Authentication. To get this to work you'll need to specify the password for login on in the same connection string. At a later stage you'll need to store this probably in a configuration file, because things like servernames, etc tend to change over time. That means you're essentially storing a password in a configuration file which is needless to say, an open door for malicous users.
I would recommend this connection string for your situation: "Initial Catalog=dals;Data Source=cerebrum;Integrated Security=SSPI"
If Windows authentication is really not an option, and you don't have the Enterprise Manager of Microsoft Sql Server, then you'll need to rerun the MSDE Setup. For more information on installing or upgrading MSDE, you can find everything in the readme file that is supplied with the latest Microsoft Sql Service Pack.
You can find the readme file here:http://download.microsoft.com/download/1/b/d/1bdf5b78-584e-4de0-b36f-c44e06b0d2a3/ReadmeSql2k32desksp4.htm
In short: Setting up MSDE with SQL Authentication and a blank SA password:
SETUP SECURITYMODE=SQL BLANKSAPWD=1
Note: Even if you have a blank SA password, you will need to specify "PWD=;..." in your connection string.
Second note: The use of blank passwords is strongly discouraged because blank passwords add a significant vulnerability to security breaches.
Best regards,

Jeroen Landheer.|||by the way, i also tried the connection string :
"Server=cerebrum;Database=dals;Integrated Security=SSPI" but still got the same error|||Can you ping "cerebrum" from the workstation on which you run your application? I've done some testing, this error is likely due to network issues. (i.e. firewall that's blocking trafic, etc.) Else you get a "login failed for user <username>" message.
For more information on configuring a firewall for SQL Server:http://support.microsoft.com/kb/287932/
|||i already ping cerebrum and there's a reply. and by the way, my colleague is using this string: "Server=cerebrum;Database=dals;User ID=sa;" on her computer but she could connect. i really don't understand why i can't connect to the server with the same connection string wherein i could connect/browse the tables in cerebrum in my server explorer of visual studio .net.|||The exact same connection string (identical) that a colleague is usingdoes not work for you? From what I can see, your connection string hasall sorts of things added onto it that your coworker isn't using.
SqlConnection connection = new SqlConnection();
connection.ConnectionString = "Server=cerebrum;Database=dals;User ID=sa;";
try {
connection.Open();
// your other code
}
catch (Exception exp) {
Trace.Write(exp.ToString());
Throw exp;
}
finally {
connection.Dispose();
}
I've had issues where using the windows integrated security in webapplications caused problems since web applications by default uses ananonymous account with very little priviledges. I don't think this isnecessarily the problem. I'd attempt to step through the issue indebug mode, and alter the data that way. From what it looks like tome, you're casting that exception without closing the connection, andthat can be a problem in itself.
Another issue that's come up in the past is the use of computernames. I know this is funny, but sometimes it doesn't resolve asproperly. I've had an old manager tell me that if you create anodbc connection to the database using the computer name (named pipe),it will eliminate the problem all together. I almost slapped himwhen he told me that, but at the same time, it actually does thetrick. I hate to use it here because of my morales as adeveloper, but it's much easier to explain.
|||

i talked to my coworker but she said it is the same connection string. i tried your code and still the same error:

SQL Server does not exist or access denied.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details:System.Data.SqlClient.SqlException: SQL Server does not exist or access denied.
Source Error:

Line 57: {Line 58: Trace.Write(exp.ToString());Line 59: throw exp;Line 60: }Line 61: finally

SqlConnection connection = new SqlConnection();
connection.ConnectionString = "Server=cerebrum;Database=dals;User ID=sa;";
try
{
connection.Open();
Label1.Text = "SQL Connection is open";
}
catch (Exception exp)
{
//Trace.Write(exp.ToString());
throw exp;
}
finally
{
connection.Dispose();
}
by the way i also tried the code in windows application and it did connect to the server.
i don't know what to do any more.

|||i don't know if this information would be of used. we have already a web application.the connections: Server=cerebrum;Database=dals;User ID=sa; same as what i am using now. but the difference is it is made in ASP and the web application I am doing right now is in C# .NET.|||

hi,

i am not sure if this information will be of use. we have web application called ManhourWeb in ASP. I am doing a web application StatusReport in C# .NET. the connection strings used in ManhourWeb application: "Server=cerebrum;Initial Catalog=dals;User Id=sa;";
i used the same connection string but the error message is Sql Server does not exist or access denied.
i have now in my computer the installed remote desktop connections of my sql server from cerebrum. jst tell me what else do i need to check. this is my first time using the sql server so i don't know much. kindly guide me if you want me to check something.

|||There is an entire KB article on possible reasons for this error:Potential causes of the "SQL Server does not exist or access denied" error message.
Also, NEVER use the sa account to access the database from applications!! Create a weak account and use that instead.

|||

i already created another account to access the database and with password. in my visual studio 2003. server explorer i am able to connect to the database. however, in my code i cant connect to the database: still the sql server does not exist or access denied.

No comments:

Post a Comment