1

I installed Sql Server Express but I need to use localhost as Datasource in connection string.

Here is the connection string now:

<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS.../>

I want to use like this:

<add name="DefaultConnection" connectionString="Data Source=localhost

Is there a way to use localhost alias instead of ".\sqlexpress" in connection string. I work in a team project and the other people use connection string like that (they have installed sql server - not express)

Can
  • 659
  • 1
  • 7
  • 24
  • 1
    If you installed SQL Server Express and told it to use the **unnamed, default** instance (instead of the `.\SQLEXPRESS` which it uses by default) - then yes, then you can connect to SQL Server Express using `localhost` (or `.` or `(local)`) – marc_s Nov 27 '17 at 13:28
  • I installed Sql Express with default options. Should i reinstall Sql Express to tell it to use unnamed, default instance? When i use localhost in web.config. I get the error "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 - The remote computer refused the network connection.)'" I'm not using Windows Authentication by the way. – Can Nov 27 '17 at 13:40
  • Default options means, you have a `SQLEXPRESS` instance name. If you want to get rid of that, then yes, you must uninstall and reinstall SQL Server Express - there's no way to change the instance name once it's installed – marc_s Nov 27 '17 at 14:56

1 Answers1

-1

You have to mention only localhost and database name like below

<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=localhost;Initial Catalog=DatabaseName;Integrated Security=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
M.Y.Mnu
  • 718
  • 8
  • 22
  • Error thrown: 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 - The remote computer refused the network connection.)' – Can Nov 27 '17 at 13:41
  • Try to resolve from [Here](https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci) – M.Y.Mnu Nov 27 '17 at 14:01