The network path was not found error message

0

I am trying to deploy my site through Filezilla. I've created database in sql server 2012 and connect my visual studio with sql server. When I run it on local server it works fine, I can easily sign in and sign out but when I deploy it on web it shows this error on con.open() line. Help please.

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.ComponentModel.Win32Exception: The network path was not found.

public partial class signinregistration : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click1(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(@"Data Source=ISL-4;Initial Catalog=Cruisedb;Integrated Security=True");
        con.Open();
        DataTable dt = new DataTable();
        SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM [Login] WHERE Email = @email AND Password = @password", con);
        using (con)
        {
            sda.SelectCommand.Parameters.AddWithValue("@email", this.textboxemail.Text);
            sda.SelectCommand.Parameters.AddWithValue("@password", this.textboxpassword.Text);

            sda.Fill(dt);

            if (dt.Rows.Count == 0)
            {
                textboxemail.Text = "";
                textboxpassword.Text = "";
                Label3.Visible = true;

                return;
            }

            string txt = textboxemail.Text;
            Session["Email"] = txt;
            Response.Redirect("index.aspx");
        }
    }
}

Source File: line 27..line 27 is con.open().

Stack Trace:

[Win32Exception (0x80004005): The network path was not found]

[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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
+5341995
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +546    
System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) +5353703    
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +145    
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +892
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +311
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData) +646    
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +278
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +38    System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +732    
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +85
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +1057    
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +78
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +196
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +146
System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +16
System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +94
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +110
System.Data.SqlClient.SqlConnection.Open() +96    
signinregistration.Button1_Click1(Object sender, EventArgs e) in \\smb-whst-www02\whst_www02$\ff8b1b\user\fareshoppers.co.uk\web\signinregistration.aspx.cs:27 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9628462
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
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) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
@MachineLearning
<?xml version="1.0"?>
    <configuration> 
        <connectionStrings> 
           <add name="ConnectionString" connectionString="Data Source=ISL-4;Initial Catalog=Cruisedb;Integrated Security=True" providerName="System.Data.SqlClient"/> 
       </connectionStrings> 
      <system.web> 
          <compilation debug="true" targetFramework="4.0">
          <assemblies>
              <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
          </assemblies>
     </compilation> 
    <customErrors mode="Off"/> 
</system.web> 
</configuration>
c#
html
asp.net
asked on Stack Overflow Aug 30, 2016 by Umair Ahmad • edited Sep 1, 2016 by Brian Tompsett - 汤莱恩

1 Answer

0

As you deploy your website using FileZilla, it copies all your web application files to the ftp folder, but your database is not copied as it is not there in your web project's path. You will find your database files (.mdf, .ldf, etc) in a folder like

C:\Program Files (x86)\Microsoft SQL Server\MSSQL.1\MSSQL\Data

But still you cannot copy your database files onto the server and use them, as database files are served by SQL Server, so the SQL Server on your server (host) shall be made aware of the database.

First requirement for this is that your hosting provider shall provide you MS SQL databases. If your current provider is not providing, then you shall look for a separate provide who can either provide you MS SQL database only or hosting with MS SQL database (you work out the financials of these options)

When your hosting provider provides you MS SQL database, you have to login into your hosting control panel and navigate to MS SQL option (whatever that can be called in your hosting provider's control panel). There you may get option to attach existing database files or crate a new database and run queries.

If you can attach database

  1. Copy your database's mdf and ldf (and other files if any) to the server and attach them using hosting control panel (you may need to stop SQL Server service to do that)

If your hosting service provider require you to create new database

  1. Then create a new database there
  2. From your local server (on your development machine) right click on database, select Tasks then Generate Script to generate your current database's script (go figure the options on SO or Google)
  3. Copy this script in the query window of your hosting control panel (wherever that option is available)
  4. run the query

For both the above cases, you will/may have to change your connection string as required (based on the database name, username that you created and its password)

Hope that helps.

answered on Stack Overflow Aug 30, 2016 by Manish Dalal

User contributions licensed under CC BY-SA 3.0