SQL server management studio local database connection error in windows 7

后端 未结 7 2072
长发绾君心
长发绾君心 2021-01-02 00:30

I\'m running SQL Server 2012 Management Studio Express in windows 7, i am having issues connecting to the local db. i tried all the above mentioned solutions, didnt work. pl

相关标签:
7条回答
  • 2021-01-02 00:47

    Try this code:

    RegistryKey rKey;
    string InstanceName;
    
    //use this string for database connection
    string ConString;
    string regPath = @"Software\Microsoft\Microsoft SQL Server\UserInstances";
    rKey = Registry.CurrentUser.OpenSubKey(regPath);
    
    if (rKey.GetSubKeyNames().Length != 0)
    {
        regPath += @"\" + rKey.GetSubKeyNames()[0];
        rKey = Registry.CurrentUser.OpenSubKey(regPath);
        InstanceName = rKey.GetValue("InstanceName").ToString();
        ConString = @"Server=np:\\.\pipe\" + InstanceName +
            @"\tsql\query;Initial Catalog=RahBord;Trusted_Connection=True";
    }
    else
    {
        Process.Start(@"C:\Program Files\Microsoft SQL Server\110\Tools\Binn\SqlLocalDB.exe", "c amirLOCALDB -s");
        regPath += @"\" + rKey.GetSubKeyNames()[0];
        rKey = Registry.CurrentUser.OpenSubKey(regPath);
        InstanceName = rKey.GetValue("InstanceName").ToString();
        ConString = @"Server=np:\\.\pipe\" + InstanceName + @"\tsql\query;Initial Catalog=RahBord;Trusted_Connection=True";
    }
    

    If your instance stopped go to this address:

    C:\Program Files\Microsoft SQL Server\110\Tools\Binn\ 
    

    and use this command

    SqlLocalDB.exe s yourInstance
    
    0 讨论(0)
  • 2021-01-02 00:54

    You can connect SSMS to a LocalDB instance using named pipes.

    1 - Get the address of a (localdb) instance by running the following command: "C:\Program Files\Microsoft SQL Server\110\Tools\Binn\SqlLocalDB.exe" info [InstanceName] (if its the default instance you're interested in, specify v11.0 as the [InstanceName] You can write it in CMD to text file with the command:

    "C:\Program Files\Microsoft SQL Server\110\Tools\Binn\SqlLocalDB.exe" info v11.0 > C:\db_details.txt
    

    2 - Copy the "Instance pipe name" value, e.g. np:\.\pipe\LOCALDB#1E0FF40B\tsql\query

    3 - Paste the "Instance pipe name" value as the Server Name.

    0 讨论(0)
  • 2021-01-02 00:54

    After two days troubleshooting, finally, I got the result If you are using express version of SQL server management studio then for local database connection, use this instead of Local****.

    Use ServerName = (LocalDb)\MSSQLLocalDB

    Image

    For more information go to the reference link - https://social.msdn.microsoft.com/Forums/sqlserver/en-US/b75bef7e-13f3-4658-8d43-9df12ab4c320/connecting-localdb-using-sql-server-management-studio-express?forum=sqlexpress

    0 讨论(0)
  • 2021-01-02 00:54
    1. open Task manager then find sqlservr.exe under the process tab
    2. make sure that the column Command Line is visible if not then click View > Select Column > Scroll Down and tick Command Line > Click OK
    3. you will see "C:\Program Files\Microsoft SQL\110\LocalDB\Binn\sqlservr.exe" -c SMSSQL11E.LOCALDB -sLOCALDB#C1E849D0 --etc
    4. Take note of the LOCALDB#C1E849D0
    5. Open SQL Management studio (runas Administrator) then in the Server name enter \\.\pipe**LOCALDB#C1E849D0**\tsql\query You should be able to browse now all the database inside the LOCALDB
    0 讨论(0)
  • 2021-01-02 00:56

    Assuming you installed SQL Server and used the named instance SQLEXPRESS, your server name should be:

    .\SQLEXPRESS
    

    Or:

    127.0.0.1\SQLEXPRESS
    

    You can check the instance name (it may not be SQLEXPRESS) and that the server is running in the Start Menu at a path very similar to this (but it will vary by version):

    Start > Programs > Microsoft SQL Server > Configuration Tools >
       SQL Server Configuration Manager

    If it is currently stopped, you need to right-click and choose Start:

    enter image description here

    You should also right-click and ensure that Startup Mode is set to automatic (this is under Properties > Service).

    The error message seems to imply that the server is trying to use named pipes. While locally it should be able to use shared memory, you should next ensure that the SQL Server Browser service is running. You can do that in:

    Control Panel > Administrative Tools > Services

    enter image description here

    If it's not started, start it, and set its Start Mode to automatic. (As above, you can do both of these things from the right-click menu.)

    If you're still not getting anywhere, it's possible you installed SQL Server 2012 without manually adding your Windows account to the group of administrators. If this is the case, hopefully you set it to use mixed mode and you can connect as sa. Otherwise you will need to use a tool like PSExec.exe to run SSMS as NT AUTHORITY\SYSTEM:

    PsExec -s -i "C:\...path to ssms...\Ssms.exe"
    

    Whether you can connect as sa or you need to connect using PSExec, the next steps are:

    1. make sure your Windows account is a login under Server > Security > Logins. If it's not there, add it by right-clicking Logins > New Login.
    2. make sure that login is a member of the sysadmin fixed server role. If it's not, make sure it is under the Server Roles tab.
    0 讨论(0)
  • 2021-01-02 00:59

    Have you checked that the TCP protocol is enabled for your particular server. Follow these instructions to see that it is enabled.

    http://msdn.microsoft.com/en-us/library/bb909712(v=vs.90).aspx

    After you enable them you must restart the service. If it fails to start check the event log for the reason why it didn’t. Common causes are that there is another service (usually another version of sql server) already running on that port. If that is the case you might need to reconfigure your server ports. Check this blog post (also includes images on how to check for TCP/IP enabled):

    http://blogs.msdn.com/b/sqlblog/archive/2009/07/17/how-to-configure-sql-server-to-listen-on-different-ports-on-different-ip-addresses.aspx

    After that the usual next barrier is the firewall or Internet security software blocking the connection. This has happened to me even on local instances. Sort that out and you should be good to go.

    If after all this you still can’t connect, search the event log for a reason.

    0 讨论(0)
提交回复
热议问题