Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What setting has to be done to connect with database with this connection string given below?

In my .exe setup having connection string

Data Source=SERVER;Initial Catalog=POS_Chimur;User ID=sa;Integrated security=false

I have to install database for this exe what settings will be needed according to above connectionString.

Till now I have installed sql server with default instance with name of pc SERVER. Still i am unable to connect with above connection string.

like image 650
Pranay Avatar asked Mar 18 '17 12:03

Pranay


Video Answer


4 Answers

You need to cheat your way in. Here's how I would approach this problem:

Data Source=SERVER;

You can create an alias to point to your final instance using "SQL Server Configuration Manager", "Aliases" enter image description here

Initial Catalog=POS_Chimur;

You need to have a database named POS_Chimur

User ID=sa;Integrated security=false

Here, you need to provide a SQL login named sa with no password. I recommend to rename actual sa account to original_sa then create a new account named sa with no password. You also need to create a user mapping for that new account in the POS_Chimur database using this code.

CREATE USER sa FOR LOGIN sa;
ALTER ROLE [db_owner] ADD MEMBER sa;

If DBO doesn't work then you can give it SysAdmin rights if you still have error.

like image 136
PollusB Avatar answered Oct 18 '22 00:10

PollusB


If you are using SQL Server security, you need to specify a username and a password, like this (where you replace 'mySApassword' with the actual password):

    Server=SERVER;Database=POS_Chimur;User Id=sa;Password=mySApassword;

In the event you want to use Windows security, you will need this connection string:

    Server=SERVER;Database=POS_Chimur;Trusted_Connection=True;

If you are running the executable on the same machine as where SQL Server is running, you can replace 'SERVER' with '.' in order to make it work on all computers, if you need to distribute it to more than one pc.

Here's some more information about SQL Server 2008 connection strings.

like image 23
Erwin Dockx Avatar answered Oct 17 '22 23:10

Erwin Dockx


I see two things mainly:

  1. You are connecting with SQL Server login

    • Go to SQL Server Management studio
    • Connect to the database server with administrative account you know and that works
    • right mouse click on the server in the 'Object Explorer' window
    • choose security
    • In the Server authentication group, choose 'SQL Server and Windows Authentication mode'
    • Restart SQL Server
  2. This account is sa and doesn't have a password

    • Go to SQL Server Management studio
    • connect to the database server with administrative account you know and that works
    • unfold the server object [-]
    • unfold the Security folder [-]
    • unfold the Logins folder => find sa login
    • right click on it and click Properties
    • In General section uncheck the Enforce password policy checkbox and clean the passwords in both text boxes
    • In Status section, make sure that Login is Enabled and that the Permissions to connect is set to Grant
    • click Ok
    • confirm, that you want to create a login with blank password (which is obviously always a risk)

After performing those steps, please log out, and try to log in again, but change the Authentication drop down value to 'SQL Server Authentication' and try to login with sa and empty password, if it works, then the connection string should be fine too.

like image 1
Jakub Szumiato Avatar answered Oct 17 '22 23:10

Jakub Szumiato


You need to mention the Provider. Your connectionstring should look like this.

Data Source=SERVER;Initial Catalog=POS_Chimur;User ID=sa;Integrated security=false; Provider="System.Data.SqlClient"

like image 1
Susheel Rawat Avatar answered Oct 17 '22 22:10

Susheel Rawat