The error message "can't connect to server" comes only when your connection is yet to be built.
You should first ensure that you are using the correct credentials to connect to your server.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi Everyone
I want to generate table script from SQL Server.
I am using below code and added in global code of object
public static class TableScriptGenerator
{
public static string GenerateTableScript(string serverInstance,string databaseName, string tableName, out string errorMessage)
{
try
{
//Server srv = new Server();
//srv.ConnectionContext.Login = login;
//srv.ConnectionContext.Password = password;
Server srv;
srv=new Server(serverInstance);
Database db= new Database();
db = srv.Databases[databaseName];
StringBuilder sb = new StringBuilder();
Table tbl = db.Tables[tableName];
ScriptingOptions options = new ScriptingOptions();
options.ClusteredIndexes = true;
options.Default = true;
options.DriAll = true;
options.Indexes = true;
options.IncludeHeaders = true;
StringCollection coll = tbl.Script(options);
string script = string.Join(Environment.NewLine, coll);
errorMessage = string.Empty; // Clear any previous error message
return script;
}
catch (Exception ex)
{
errorMessage = ex.Message; // Assign the error message to the output variable
return null;
}
}
}
and I am calling function Generate Table script in code stage of object
string serverInstance = "abc\\SQLEXPRESS";
string databaseName = "Demo";
string tableName = "humanresources";
string script;
string errorMessage;
script = TableScriptGenerator.GenerateTableScript(serverInstance,databaseName, tableName, out errorMessage);
OutputVariable = script;
ErrorMessageOutputVariable = errorMessage;
In this I have added OutputVariable and ErrorMessageOutputVariable are output variables
I have added required dll's and namespace
I am getting error like cant connect to server
If anyone have idea on this, please help me on this
Thanks,
Soumya
The error message "can't connect to server" comes only when your connection is yet to be built.
You should first ensure that you are using the correct credentials to connect to your server.