An error has occurred while establishing a connection to the server

W

weird0

I have written a webservice locally, and upon consuming or testing it
in the explorer there is a problem.
It throws the following exception:

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 allow remote connections.
(provider: Named Pipes Provider, error: 40 - Could not open a
connection to SQL Server).

I think the problem seems to be with the connection string. Here is
it:

public static string connectionString = @"server=amirdiwan;database=|
DataDirectory|\BankingDb.mdf;";

I havent sepcifed the exact directory as the db lies my desktop
folder. Should i write that instead of just DataDirectory? Should I
write the servername as "amirdiwan" which i got from hostname from my
console or "localhost" which is the name of the webreference that i
added?

Please, somebody rephrase my connection string.....

Would be grateful.
 
H

Hakan Fatih YILDIRIM

hi,

you can use osql utility on command prompt : osql -E -
Stcp:servername\instancename or
 
W

weird0

or you can add Network=DBMSSOCN to your connectionstring

You mean this is what my connectionstring should be:

public static string connectionString =
@"Network=UIC;server=amirdiwan;database=|DataDirectory|
\BankingDb.mdf;";

If the code does not know where exactly the db lies, how will fetch
it? Is there some built-in fetching inside the compiler?

Please explain in detail....

Thankyou
 
K

Koliber (js)

You mean this is what my connectionstring should be:

public static string connectionString =
@"Network=UIC;server=amirdiwan;database=|DataDirectory|
\BankingDb.mdf;";

If the code does not know where exactly the db lies, how will fetch
it? Is there some built-in fetching inside the compiler?

Please explain in detail....

Thankyou

As far as I know Not in a compiler but it is build in system
(windows). I have other problem I am usling SMO library
and try to enumerate sql server services in loop find my
instance MYCOMP\FOTOPROG using such code

ManagedComputer mc = new ManagedComputer(sServerName);

string sMessage = "";
foreach (Service svce in mc.Services)
{
sMessage += String.Format("{0} -- {1} -- {2} -- {3} --
{4}\n",
svce.DisplayName, svce.Name, svce.ServiceAccount,
svce.ServiceState, svce.StartMode);
}

System.Windows.Forms.MessageBox.Show(sMessage, " " + mc.Name);

but it only get in mc.Services and shows to me two services
MSSQL$SQLEXPRESS (login type .\tomaszk ) and SqlBrowser (login type
NT AUTHORITY\NetworkService) but no my instance which is MSSQL
$FOTOPROG
and is on a service list and is started (login by .\tomaszk and also
with local
system acount
And I do not know why it does not work and tryin to investigate it and
lern
about this all acounts and privileges and also SMO and WMI for rev
about five
days

TIA
KENOBI
 

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