Search code examples
c#sql-serverconnection-stringwindows-server-2012

Connectionstring for windowsServer


I have to create windows application with C#.

I have using this connection string:

SqlConnection conn = new SqlConnection(
                   "Data Source=(local);Initial Catalog=MyDBname;Integrated Security=SSPI;"
                    );

Every thing is good,but when I have to copy "debug folder" to the server(and restore DB to the server), my Connectionstring doesn't work.

By the way, both of SQL in client side or Server side doesn't need username and password.


Solution

  • First of all: Use the SqlConnectionStringBuilder instead of hardcoding the connection string. That way you can make sure you always get a properly formatted connection string.

    Second idea: Is the SQL Server instance name also valid for the server? (local) identifies the locally running SQL Server instance without and instance name. As soon as your server has an instance name, like for example SQL2012, you need to use local\SQL2012.

    When connecting your SQL Server Management Studio to the server's database, which name do you use there? Does the user your application runs under on the server actually have the rights to access the server and the database?