简体   繁体   English

使用下面给出的连接字符串连接数据库需要做什么设置?

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

In my .exe setup having connection string 在我的.exe设置中有连接字符串

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. 我必须为此exe安装数据库,根据上面的connectionString将需要什么设置。

Till now I have installed sql server with default instance with name of pc SERVER . 到目前为止,我已经安装了sql server,其默认实例名称为pc SERVER Still i am unable to connect with above connection string. 仍然我无法连接上面的连接字符串。

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" 您可以使用“SQL Server配置管理器”,“别名”创建别名以指向最终实例 在此输入图像描述

Initial Catalog=POS_Chimur;

You need to have a database named POS_Chimur 您需要一个名为POS_Chimur的数据库

User ID=sa;Integrated security=false

Here, you need to provide a SQL login named sa with no password. 在这里,您需要提供一个名为sa且没有密码的SQL登录名。 I recommend to rename actual sa account to original_sa then create a new account named sa with no password. 我建议将实际的sa帐户重命名为original_sa,然后创建一个名为sa且没有密码的新帐户。 You also need to create a user mapping for that new account in the POS_Chimur database using this code. 您还需要使用此代码在POS_Chimur数据库中为该新帐户创建用户映射。

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. 如果DBO不起作用,那么如果仍有错误,可以给它SysAdmin权限。

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): 如果您使用的是SQL Server安全性,则需要指定用户名和密码,如下所示(将mySApassword替换为实际密码):

    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: 如果您要使用Windows安全性,则需要此连接字符串:

    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 '.' 如果您在运行SQL Server的同一台计算机上运行可执行文件,则可以将“SERVER”替换为“。” in order to make it work on all computers, if you need to distribute it to more than one pc. 为了使它适用于所有计算机,如果您需要将其分发到多台PC。

Here's some more information about SQL Server 2008 connection strings. 以下是有关SQL Server 2008连接字符串的更多信息。

You need to mention the Provider. 您需要提及提供商。 Your connectionstring should look like this. 您的connectionstring应如下所示。

Data Source=SERVER;Initial Catalog=POS_Chimur;User ID=sa;Integrated security=false; 数据源= SERVER;初始目录= POS_Chimur;用户ID = sa;集成安全性=假; Provider="System.Data.SqlClient" 供应商= “System.Data.SqlClient的”

I see two things mainly: 我主要看两件事:

  1. You are connecting with SQL Server login 您正在连接SQL Server登录

    • Go to SQL Server Management studio 转到SQL Server Management工作室
    • 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' 服务器身份验证组中,选择“SQL Server和Windows身份验证模式”
    • Restart SQL Server 重新启动SQL Server
  2. This account is sa and doesn't have a password 此帐户是sa ,没有密码

    • Go to SQL Server Management studio 转到SQL Server Management工作室
    • 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 展开Logins文件夹=>查找sa登录
    • 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. 执行这些步骤后,请注销,然后尝试再次登录,但将身份验证下拉值更改为“SQL Server身份验证”并尝试使用sa和空密码登录,如果有效,则连接字符串应该没问题太。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 web.config中连接SQL Server数据库的连接字符串是什么? - What is the connection String to connect to the SQL Server database in web.config? 这个数据库的连接字符串是什么 - what is the connection string for this database 如何访问连接字符串并连接到数据库 - How to access connection string & connect to database 为什么我不能通过连接字符串连接到数据库? - Why I cant connect to the database by connection string? 带有无效查询的数据库表损坏:它做了什么并将回滚? - Corrupted database table with invalid query: what has it done and will it roll back? 什么是 sql server 连接字符串中的“连接超时”? - What is “Connect Timeout” in sql server connection string? 打开“连接”,“连接字符串”,我的数据库名称是什么? - Open Connection, Connection String, what's my database name? 以另一用户身份连接到同一数据库,而无需对连接字符串进行硬编码 - Connect to the same database, but as a another user, without hardcoding a connection string 如何从存储在表中的连接字符串连接到 SQL Server 数据库? - How to connect to a SQL Server database from a connection string stored in a table ? 使用连接字符串连接数据库时出错,并且附加数据库文件时出错 - Error in connect to database with connection string AND error to attach a db file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM