显示标签为“SQLServer”的博文。显示所有博文
显示标签为“SQLServer”的博文。显示所有博文

2014年6月11日星期三

SQL SERVER 2008 r2 sa和windows账号都无法登录

处理方式:
  1. 停止正在运行的sql server服务;
  2. 在cmd中切换到sql server目录中的Binn目录(如果这个路径在path环境变量中不切换也行),运行sqlservr.exe -m,注-m为单用户模式的参数,这个cmd窗口不能关闭;
  3. 新打开一个cmd窗口,执行如下语句,如果你知道是什么意思,这一步可以用Microsoft SQL Server Management Studio来代替,(以下操作sqlcmd.exe所在路径在path环境变量中):
    C:\Users\Administrator>sqlcmd
    1> create login tempsa with password='tempsa@123'
    2> go
    1> sp_addsrvrolemember 'tempsa','sysadmin'
    2> go
  4. 关闭这两个cmd窗口,启动sql server服务,使用上一步创建的用户登录,重置/修改一下sa的密码,这时sa就可以登录了

2014年5月17日星期六

SQL Server 无法连接(Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

.net web程序运行时出错:

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)

1、查看原因是数据库没有启动,然后尝试启动数据库,无法启动并报错。

2、查看windows日志->应用程序日志,找到SQL Server的错误日志,可以看到错误日志EventID为17058。然后解决EventID:17058的问题。


出现错误:SQL Server默认实例(MSSQLSERVER)无法启动,错误代码:17058


日志错误信息:
initerrlog: Could not open error log file 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\ERRORLOG'. Operating system error = 5(Access is denied.).

The event ID in the application log is 17058. Also the following error message appears in the system log 

The SQL Server (MSSQLSERVER) service terminated with service-specific error 17058 (0x42A2).

分析原因:安装AD后,系统改为使用域用户登陆,原先安装SQL时设置的“本地用户”信息已经修改,当前(域)用户没有权限访问MSSQLSERVER实例文件夹或整个SQL文件夹

解决方法:
1、打开“服务”,找到SQL Server(MSSQLSERVER)服务(或设置实例所对应的服务),查看属性,在“登陆”标签中选择“本地系统账户”


2、为保险起见,进行这步操作:打开SQL Server Configuration Manager(SQL Server配置管理器),在SQL Server Service(SQL Server服务)中找到对应实例(名称和“服务”中的名称相同)。在“登陆”标签中选择“内置账户”,并选择“Local System”(全其他如NETWORK SERVICE也可以,但要保证有权限)

3、启动SQL Server(MSSQLSERVER)服务。

4、如果还是出错(如126错误),那么进入SQL Server的安装目录,给整个安装目录分配NETWORK SERVICE及当前登录用户的权限,特别是实例所在目录,以及数据库文件相关目录,分配写权限。完成后再次启动服务。

结果:成功启动SQL Server(MSSQLSERVER)服务。