Showing posts with label sqlclient. Show all posts
Showing posts with label sqlclient. Show all posts

Monday, March 19, 2012

Could not open a connection to SQL Server

Hi,

Has somebody had a problem like this before?

Exception Details: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 thefact that under the default settings SQL Server does not allow remoteconnections. (provider: Named Pipes Provider, error: 40 - Could notopen a connection to SQL Server)

That's part of the code:

SqlConnection con;
string sql;
SqlCommand cmd;

con=new SqlConnection("Data Source=elf/SQLEXPRESS;Initial Catalog=logos;Integrated Security=SSPI;");
sql="SELECT max(id_kandydat) from Kandydat";
con.Open();
cmd=new SqlCommand(sql,con);
int id = Convert.ToInt32(cmd.ExecuteScalar());

con.Close();

SqlDataSource7.InsertCommand="INSERT INTO Kandydat_na_Kierunek(id_kandydat, id_kierunku, id_stan) VALUES ("+"'"+id+"'"+","+"'"+DropDownList1.SelectedValue+"'"+","+'1'+");";

I don't really get it. I'm nearly 100% sure that before some changes in my project this had worked perfectly. Does anybody have any idea how to make it work again? I would be very grateful for any help. And, yesy, I know it is quite common error, but proposed solution found didn't help.

Regards,

N.

Hi there,

In the SQL Management Studio, RightClick the SQL server instance, Choose
Properties, and under Select a Page list, click Connections. Now you should
see a checkbox labelled "Allow Remote Connections to This Server". Make sure
it is checked.

Check this link...

http://support.microsoft.com/default.aspx?scid=kb;EN-US;914277

Hope this may helps you

Srinath

|||Hi,Thank you for your advice. The remote connection has already been set on.|||

Hi

From your description, it seems that you met error when you are trying to connect to your SQLServer,right?

First, you should make sure that if 1433 port has been enabled on your server, which is the default port for SQLServer remote connections.

And Generally, you can try the following ways to handle your problem.

1. Enable remote connections for SQL Server 2005 Express or SQL Server 2005 Developer Edition
2. Enable the SQL Server Browser service
3. Create exceptions in Windows Firewall
4. Create an exception for SQL Server 2005 in Windows Firewall
5. Create an exception for the SQL Server Browser service in Windows Firewall

More details for each step, you may see the following link:

http://support.microsoft.com/default.aspx?scid=kb;EN-US;914277

Thanks.

|||

Thank you. Remote connection for both servers are enabled (always have been). Windows Firewall is shut; no other firewall is running. It does in fact work locally.

Regards,

N.

|||

Hi,

Then, let's back to your connection string.

con=new SqlConnection("Data Source=elf/SQLEXPRESS;Initial Catalog=logos;Integrated Security=SSPI;");

It seems that you are connecting to a SQLExpress instance, Generally, if you are using SQLExpress, you should assign the AttachDBFilename, but not the InitialCatalog.

See the following sample string:

data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|YouDataBaseName.mdf;User Instance=true providerName="System.Data.SqlClient"

Thanks.

Thursday, March 8, 2012

Could not find stored procedure "addUser" - Please help

Hi ,

Can someone tell me why I am getting the following error while I am trying to add users in a database.:

:System.Data.SqlClient.SqlException Could not find stored procedure "addUser"

where should we normally keep our stored procedures? ( i am new to sql server)

thank you in advance

I presume that addUser is an sp that you have written? If so which database was it create in and which database is your current one?

As an example for many connections master is the default database so it may be created there and you are trying to run in the application database? Or you could be in master now and the SP could be in your database. You can fix this by always doing a "use database" before you run any commands

|||From the point that addUser is not a procedure written by you, I have to tell you that there is actually no adduser procedure in SQL Server by default. Users are created by using the CREATE USER commands and no SP. If you mean the (tobe) deprecated procedurte sp_adduser, you sure have to call it with the right name that you can access it the whole name is that with the sp_ writte in front of your mentioned procedure.

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de