Visual Studio 2017 - SQLServer连接错误 [英] Visual Studio 2017 - SQLServer Connection Error

查看:295
本文介绍了Visual Studio 2017 - SQLServer连接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Everyone, 


我正在尝试下面的代码导致连接错误。重要笔记;我使用的是本地数据库,我可以使用SSMS连接。我在服务器名和数据目录中放置了****。我正在使用VS 2017和SQLServer 2014.


private void btnConnect_MouseClick(object sender,MouseEventArgs e)

        {

            string cs = @" Data Source = *********** \ SQLEXPRESS; Initial Catalog = AA *****; Integrated Security = True";

           使用(SqlConnection con = new SqlConnection(cs))

               试试
                {

$
                    con.Open();

                    MessageBox.Show("与sql server连接");

                    con.Close();



                }¥b $ b            catch(例外情况)

            {

                MessageBox.Show(es.Message);

            }


消息错误 - 无法打开数据库"AA *****"登录请求。登录失败。用户'domain\aduser'登录失败 


非常感谢任何帮助。

解决方案

您说您正在使用LocalDB,然后连接示例位于链接中。


http://www.michael-whelan.net/sql-server-localdb-2014-connection-string/


您尝试使用的是将MDF文件移动到MS SQL Express目录并将
附加 MDF文件移动到数据库引擎时。



Hello Everyone, 

I am trying the code below which results in a connection error. Important notes; I am using a local DB, I can connect using SSMS. I placed **** in the servername and data catalog. I am using VS 2017 and SQLServer 2014.

private void btnConnect_MouseClick(object sender, MouseEventArgs e)
        {
            string cs = @"Data Source=***********\SQLEXPRESS;Initial Catalog=AA*****;Integrated Security=True";
            using (SqlConnection con = new SqlConnection(cs))
                try
                {

                    con.Open();
                    MessageBox.Show("connect with sql server");
                    con.Close();

                }
            catch (Exception es)
            {
                MessageBox.Show(es.Message);
            }

Message Error - Cannot open database "AA*****" requested by the login. The login failed. Login failed for user 'domain\aduser" 

Any help is much appreciated.

解决方案

You say you are using LocalDB, then the connectionsting example is in the link.

http://www.michael-whelan.net/sql-server-localdb-2014-connection-string/

The one you are trying to use is when you move the MDF file to the MS SQL Express directory and Attach the MDF file to the database engine.


这篇关于Visual Studio 2017 - SQLServer连接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆