Click here to Skip to main content
12,064,291 members (56,010 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: SQL-Server SQL-Server-2008 , +
Sql server details are as follows
SERVER TYPE==>Database Engine
SERVER NAME==>INVISIBLE_LINK
AUTHENTICATION TYPE==>sqLSERVER AUTHENTICATION
USER NAME==>sa
PASSWORD==>password@123
IPADDRESS==>127.0.0.1
port==>1433


my web.config file codes
<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
 
<configuration>
 
  <connectionStrings>
    <add name="SqlConnectionString" connectionString="Data Source=127.0.0.1:1433;Initial Catalog=Qmanager;User ID=sa; Password=password@123; Connection Timeout=60" providerName="System.Data.SqlClient" />
 
  </connectionStrings>
</configuration>
Examine the connection string.After having manipulated i can't able to run a simple query even.


public  class Ticket
    {
       public string constr;
        public void newticket(int ticketno, string Cust_name, string reason)
        {
            //constr="Data Source=INVISIBLE_LINK;Initial Catalog=Qmanager;User ID=sa; Password=password@123; Connection Timeout=60";
            Console.Write(constr);
            SqlConnection conn = new SqlConnection(constr);
            SqlCommand comm = new SqlCommand();
            
            comm.CommandText = "Insert into Ticketss values ('" + ticketno + "','" + Cust_name + "'," + DateTime.Now.Date + ",'N','"+reason+"')";
            comm.Connection = conn;
            conn.Open();
            comm.ExecuteNonQuery();
            conn.Close();
 
        }
protected void Button2_Click(object sender, EventArgs e)
   {
       Entity.Ticket obj = new Ticket();
     obj.constr = System.Configuration.ConfigurationManager.ConnectionStrings[0].ConnectionString.ToString();
       string val = Application[0].ToString();
       obj.newticket(Convert.ToInt16(val), TextBox2.Text.ToString(), DropDownList1.SelectedItem.ToString());
 
   }
after running the code I only get the following message

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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Source Error:
Line 35:         obj.constr = System.Configuration.ConfigurationManager.ConnectionStrings[0].ConnectionString.ToString();
Line 36:         string val = Application[0].ToString();
Line 37:         obj.newticket(Convert.ToInt16(val), TextBox2.Text.ToString(),    DropDownList1.SelectedItem.ToString());
Stack Trace:
[SqlException (0x80131904): 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5009598
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
   System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity) +341
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) +129
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) +270
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +195
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +232
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +5023255
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +33
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +524
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
   System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +479
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +108
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126
   System.Data.SqlClient.SqlConnection.Open() +125
   Entity.Ticket.newticket(Int32 ticketno, String Cust_name, String reason) +296
   Default2.Button2_Click(Object sender, EventArgs e) in e:\AC_DB\WebSite2\kioskdesk.aspx.cs:37
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
Posted 16-May-12 19:26pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Start with:
Changing Data Source=127.0.0.1:1433; to Data Source=.; in your web.config file. What you use looks like default instance & port.


If it is not resolved then follow these to find/resolve issue:

1) Make sure your server name is correct, e.g., no typo on the name.
2) Make sure your instance name is correct and there is actually such an instance on your target machine. [Update: Some application converts \\ to \. If you are not sure about your application, please try both Server\Instance and Server\\Instance in your connection string]
3) Make sure the server machine is reachable, e.g, DNS can be resolve correctly, you are able to ping the server (not always true).
4) Make sure SQL Browser service is running on the server.
5) If firewall is enabled on the server, you need to put sqlbrowser.exe and/or UDP port 1434 into exception.

Details here: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified[^]

There is a tool to eliminate/confirm few steps, have a look at section 'Update May 2009' in the article.
  Permalink  
Comments
niraj.1991 17-May-12 4:24am
   
I cant able to ping the 127.0.0.1:1433
but im able to ping 127.0.0.1
Sandeep Mewara 23-May-12 2:54am
   
That simply means that your port 1433 is closed and thus you are having issue. Either open the 1433 port or use any other already open port.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160204.4 | Last Updated 17 May 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100