今天剛上班,一個同事找我,說我連不上數據庫了,報錯。此為背景
把錯誤貼出來先
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、SQL Server的服務全部啟動
2、服務端設置為允許遠程連接
3、啟用SQL Server服務端的網絡協議中的TCP/IP協議和Named Pipes協議
4、防火牆中設置1433端口例外
或許再將RemoteDacEnabled設置為true?
好吧,我能想到的就這么多了。
下面是連接字符串
Data Source=IP\實例名;Initial Catalog=DB_Name;Persist Security Info=True;User ID=UserID;Password=******
有錯嗎?沒錯吧?這個真沒錯。但為什么還連不上呢。
她在程序里直接聲明了一個字符串,然后把上面一段賦給這個字符串,再創建連接。沒錯,流程也沒錯。但就是連不上。
我就把我所了解的這以上點都翻來覆去做了個遍,結果還是不行,要崩潰了......
1、SQL Server的服務全部啟動
全部已啟動
2、服務端設置為允許遠程連接
已設置為允許
3、啟用SQL Server服務端的網絡協議中的TCP/IP協議和Named Pipes協議
全部開啟
4、防火牆中設置1433端口例外
telnet通
中午吃完飯,在外面被太陽曬了一下,回來睡了一覺。醒了擦擦眼睛,看看新聞,誒,想起來了!!讓我們再看看這個字符串啊
Data Source=IP\實例名;Initial Catalog=DB_Name;Persist Security Info=True;User ID=UserID;Password=******
她的寫法:string conn = "Data Source=IP\實例名;Initial Catalog=DB_Name;Persist Security Info=True;User ID=UserID;Password=******";
那個斜杠大家看到了吧,就是個轉椅字符啊。。。淚奔了。。。
前面加了個at,連上了。。。
這個問題,有夠弱智吧,但就是發生了。網上好多說這個也配了,那個也設了的同學,看看你是不是跟我遇到的問題一樣呢?