Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
2.18/5 (5 votes)
i want to connect sql server in client system but..

i have an error like

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - No connection could be made because the target machine actively refused it.)


web.config

C#
<configuration>
    <configSections>
    </configSections>
    <connectionStrings>
        <!--<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\demo.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>-->
      <add name="ConnectionString" connectionString="Data Source=192.168.0.82,1433;Network Library=DBMSSOCN;Initial Catalog=NewsAdvt;User ID=sa;Password=sql;" providerName="System.Data.SqlClient"/>
    </connectionStrings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>


Form Code

C#
db = DatabaseFactory.CreateDatabase("Connectionstring");
           dbCommand = db.GetSqlStringCommand("select max(GroupCode) from AccountGroup");
           DataSet ds = db.ExecuteDataSet(dbCommand);


error line is DataSet ds = db.ExecuteDataSet(dbCommand);

I can't find the error, what can i do ?


Regards
AR
Posted
Updated 20-Dec-13 0:28am
v8

When you install MS SQL Server on local machine, its instance (by default) is visible on local computer only. If you want to use MS SQL Server in LAN, you need to enable TCP/IP connections.
Please, read this: Enabling Network Access to SQL Server Express[^]

If it won't help, please try to connect to MS SQL Server via instance:
Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername;
Password=myPassword;
instead of IP address.
http://www.connectionstrings.com/sql-server/[^]
 
Share this answer
 
v2
Comments
An@nd Rajan10 20-Dec-13 3:11am    
it is more confusing...
Maciej Los 20-Dec-13 3:18am    
Answer has been updated!
An@nd Rajan10 20-Dec-13 4:37am    
thank you
what is mean by myInstanceName ?
Maciej Los 20-Dec-13 6:32am    
Have a look at example ;)
An@nd Rajan10 20-Dec-13 6:35am    
Yes,that why i ask you !
my mistake is the manual problem in server computer and client computer that is may be the configuration manger -> tcp\ip set as enable and protocol as enable...


C#
<connectionstrings>
   <add name="ConnectionString" connectionstring="Data Source=192.168.0.82,1433;Network Library=DBMSSOCN;Initial Catalog=NewsAdvt;User ID=sa;Password=sql;" providername="System.Data.SqlClient" />
 </connectionstrings>
 <startup uselegacyv2runtimeactivationpolicy="true">
   <supportedruntime version="v4.0" sku=".NETFramework,Version=v4.0" />
 </startup>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900