尝试使用Microsoft.SqlServer.Management.Smo连接sql server 2008时出现连接错误 [英] connection error trying to connect sql server 2008 using Microsoft.SqlServer.Management.Smo
问题描述
我正在尝试使用
i am trying to run script file using
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
但我得到与服务器有关的错误
错误:
but iam getting error in connection with server
Error:
{无法连接到服务器数据源=(本地);初始目录= DatabaseName;用户ID = sa;密码= 123123;。}
{"Failed to connect to server Data Source=(local);Initial Catalog=DatabaseName;User ID=sa; Password=123123;."}
my代码是
my code is
FileInfo file = new FileInfo(filePath);
string script = file.OpenText().ReadToEnd();
string conn = "Data Source=.;Initial Catalog=edustarsDBwithFeesPayments;User ID=sa; password=123123;";
Server server = new Server(new ServerConnection(conn));
server.ConnectionContext.ExecuteNonQuery(script);
i也试过很多类型的连接字符串,但仍然得到同样的错误。< br $>
i also tried many types of connection string but still getting same error.
异常详细信息:System.ComponentModel.Win32Exception:找不到网络路径
Exception Details: System.ComponentModel.Win32Exception: The network path was not found
推荐答案
我也试过很多类型的连接字符串
i also tried many types of connection string
没有它赢了没有帮助。给出正确的路径
看看这个:
string conn =数据源=。; 初始目录= edustarsDBwithFeesPayments;用户ID = sa;密码= 123123;;
DataSource =。 ? :doh:
给datasource.Likewise提供正确的服务器地址,数据库,用户名,密码一切正确
请参阅更多详情:
https://www.connectionstrings.com/ [ ^ ]
No it won't help.Give the correct path
Look at this:
string conn = "Data Source=.; Initial Catalog=edustarsDBwithFeesPayments;User ID=sa; password=123123;";
DataSource= . ? :doh:
Give correct server address to datasource.Likewise,Database,username,password everything should be correct
and please see for more details:
https://www.connectionstrings.com/[^]
FileInfo file = new FileInfo(filePath);
string script = file.OpenText().ReadToEnd();
string ServerName= "ABDUSSALAM";
Server server = new Server(ServerName);
server.ConnectionContext.ExecuteNonQuery(script);
新服务器(ServerName);
在这个构造函数中我们可以给出两种类型的参数,一种是连接字符串,一种是服务器名称
我用服务器名替换连接字符串,它完成了trik。
new Server(ServerName);
in this constructor we can give two type of parameters one is connection string and one is server name
I replace connection string with Server Name ans it done the trik.
这篇关于尝试使用Microsoft.SqlServer.Management.Smo连接sql server 2008时出现连接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!