|
Looking forward to it!
Been looking for some examples on this!
|
|
|
|
|
I created an app in VB that used SQLDMO to script objects in an SQL database. I am trying to write one in C# and I have run into a problem. In order to script user defined functions you need to reference "SQLDMO._Database2". However, I get the following error
Cannot implicitly convert type 'SQLDMO._Database' to 'SQLDMO._Database2'
when trying to execute this line
SQLDMO._Database2 ndb = svr.Databases.Item(a+1,"dbo");
I don't understand why this is happening, I also changed the following reference
SQLDMO.SQLServer svr = new SQLDMO.SQLServerClass();
to
SQLDMO.SQLServer2 svr = new SQLDMO.SQLServer2Class();
and I still get the same error. Any ideas???
|
|
|
|
|
I tried this and it worked fine:
ArrayList funcs = new ArrayList();
foreach( SQLDMO.Database2 db2 in srv.Databases )
{
foreach( SQLDMO.UserDefinedFunction func in db2.UserDefinedFunctions )
{
funcs.Add( func.Name );
}
}
I think that the problem may be the SQLDMO._Database2. Just use SQLDMO.Database2 (without the underscore) instead.
And one other thing, I declare my sql server this way:
SQLDMO.SQLServer srv = new SQLDMO.SQLServer();
Hope that helps.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
I made the changes that you suggested but I am still getting the same error. Here is the code that I am using. I have changed it to reflect some of your suggestions.
<code>
SQLDMO.SQLServer svr = new SQLDMO.SQLServer();
svr.Connect(SVRName,"username","password");
//I loop through the databases to see if it is in the list
for(int a=0;a <= svr.Databases.Count;a++)
{
if(svr.Databases.Item(a+1,"dbo").Name == DBName)
{
//If it is in the list I need to set the database but
//Here is the line that gives me the error
SQLDMO.Database2 db = svr.Databases.Item(DBName,"dbo");
for (int b = 0; b <= m_ScriptFlags.Count - 1; b++)
{
FlagItem = m_ScriptFlags[b].ToString();
if (m_ScriptFlags[b].ToString() == "UDF")
for (int c = 0; c <= db.UserDefinedFunctions.Count ; c++)
//Then do the scripting or whatever needs to be done
</code>
|
|
|
|
|
I recently wrote an article[^] for codeproject where the application involved uses a utility class for generating scripts. Here is the pertinent method from that class:
public static string GetScript(string hostName, string dbName, string username, string password, string prefix )
{
SQLDMO.SQLServer srv = new SQLDMO.SQLServer();
if( username.Length <= 0 )
{
srv.LoginSecure = true;
srv.Connect( hostName, "", "" );
}
else
srv.Connect(hostName, username, password );
SQLDMO.SQLDMO_SCRIPT_TYPE param = SQLDMO_SCRIPT_TYPE.SQLDMOScript_Default |
SQLDMO.SQLDMO_SCRIPT_TYPE.SQLDMOScript_Indexes |
SQLDMO_SCRIPT_TYPE.SQLDMOScript_Drops |
SQLDMO_SCRIPT_TYPE.SQLDMOScript_OwnerQualify;
string script = "";
foreach(SQLDMO.Database db in srv.Databases)
{
if(db.Name!=null && db.Name.ToLower().Equals(dbName.ToLower()) )
{
foreach( SQLDMO.Table table in db.Tables )
{
if( table.Name.ToLower().StartsWith( prefix.ToLower() ) )
{
script += table.Script( param, null, null, SQLDMO.SQLDMO_SCRIPT2_TYPE.SQLDMOScript2_Default );
}
}
foreach( SQLDMO.StoredProcedure proc in db.StoredProcedures )
{
if( proc.Name.ToLower().StartsWith( prefix.ToLower() ) )
{
script += proc.Script( param, null, SQLDMO.SQLDMO_SCRIPT2_TYPE.SQLDMOScript2_Default );
}
}
break;
}
}
return script;
}
Notice that I don't use the Databases.Item method. Instead I iterate through until I find the one with the name equal to the name of the db I want. I'm not sure if this matters, but hopefully it can be of some help.
Also notice that I am not using the Database2 object, however, after a few tests with using the same code and the Database2 object instead on my local machine, I am convinced it does work the way you expect--it will just provide you with the list of functions you need instead sprocs and tables.
Best Regards.
-Matt
p.s. All of this *may* be a moot point if you don't have the latest service pack for SQL Server 2K, though this is just a hunch and may not be related and/or causing the problem.
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
Thanks! I have noticed that it works when you iterate through until you find the one that you are looking for. In VB you could just reference the object you wanted and go on from there. Here is another gotcha that I know I am going to run into. In the scripting app I wrote in VB I could get the dependencies of the views. This was handy for the DBA when running the script (all in one file). This did away with the errors stating invalid object name due to a view referencing another view that hadn't been created yet but it was further down in the script. By chance have you done anything with the dependencies?
|
|
|
|
|
Unfortunately, no. Following dependencies is something that I've been wanting to learn more about, but haven't had the time. I'm just waiting for a project to come around where I will be forced to learn it.
Good luck.
-Matt
------------------------------------------
The 3 great virtues of a programmer:
Laziness, Impatience, and Hubris.
--Larry Wall
|
|
|
|
|
I'm making a traffic shaper for Windows in c#. So far I've got the monitoring part, but I was breaking my head over the part to limit peoples bandwidth. What I need to do is (literally):
"shaping incoming packets is done indirectly through the outgoing queues (by scheduling TCP ACK packets)"
Any idea how i can schedule these packets?
|
|
|
|
|
Hello friends I want to make a mirror print to any document,take this document and send to printer whit a printing mirror,this printer is available for this,sorry for my english,help me!!
S.
bigmega
|
|
|
|
|
I suspect you'll need to print to a bitmap, flip that then print it.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
christian I need to print a word document in mirrored output,I want something that let me take any document not bitmap and make mirroring ,can do behind the send the command the printer or make a flip created for me,understand me??
S.
bigmega
|
|
|
|
|
Yes, I understood you the first time. I still don't know that it can be done, that is, I doubt you can tell a printer to flip the image, and I don't know of any way to flip what you're sending, unless you can put it onto a bitmap first, and then flip that.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
I have a large DataTable (67,000 records) and I need to perform an operation on just one column.
As an example, if I wanted to set all characters to upper case, I would consider using something like:
<br />
foreach (System.Data.DataRow row in myDataTable.Rows) <br />
{<br />
string lower = row[ColumnNumber].ToString();<br />
row[ColumnNumber] = lower.ToUpper();<br />
} <br />
Having tested the above code, it takes approx 60mins to update the entire data table on a 1.3ghz PC with 256mb ram.
Is there a more efficient method?
Regards
Wayne Phipps
____________
Time is the greatest teacher... unfortunately, it kills all of its students
LearnVisualStudio.Net
|
|
|
|
|
Couple things:
Although I've never really tested it, I've heard anecdotally that foreach is not a very efficient way to do things. You can try for(int i=0;i < myDataTable.Rows.Count;i++) and then refering to myDataTable.Rows[i] inside of the loop.
More significantly: I think you should reconsider pulling 67000 rows into your client application. If you need to change that large a chunk of data, doing it in SQL on the database server will likely be faster.
Just my $0.02...Hope it helps,
Bill
|
|
|
|
|
Thanks for your reply. I'll give it a try.
Unfortunately I don't have much choice over pulling all that data in because it's been exported from a legacy system that used its own format for data storage.
Basically we've got to pull it in before we can push it into something else more usefull.
Weve developed this application because no SQL server or MS Access is available on the client PCs where data has to be manipulated.
Its a case of "If it takes an hour, it takes an hour" but it would be great to reduce this as much as possible.
I'm willing to try anything anyone can think of.
Regards
Wayne Phipps
____________
Time is the greatest teacher... unfortunately, it kills all of its students
LearnVisualStudio.Net
|
|
|
|
|
There are several things you could do. The DataTable is a damn heavy object which is relatively slow compared to other data structures. This is the price you pay for the complexity of the class. So your first thought should be about another datacontainer.
If you have relationships to other tables, a primary key set or active views on the datatable: Remove them, make your operation and readd. This way many checks while you update your data will be left out.
Also try to call BeginLoadData() and EndLoadData(). I dont know if it increses performance in updates (as it does while adding) but its worth a try.
|
|
|
|
|
Hello,
I wanna write a multithreaded application and I am in need of a feature which is known to me in MFC, but I am unaware of in .NET.
The problem is that I wanna spawn a worker thread from one of my forms. I can pass data to my worker thread from my dialog, but it is not enough to me, I also have to manipulate the UI controls of the caller from my worker thread. In MFC one can pass a pointer of the caller dialog to one's worker thread, which does the job.
I am sure, there must be a similar thing in .NET too.
Please help!
Thanks in advance.
Peter Molnar
|
|
|
|
|
|
Control has an Invoke method that should be used when you need to update a control from a thread other than the one that created it. Use InvokeRequired to determine whether it is necessary to use Invoke .
Charlie
if(!curlies){ return; }
|
|
|
|
|
I tried to insert a record to database(in user register operation) using Access 2003 database and an exception appears("this operation must use updateable queries.").But when i use the same code with SQL2000 Database,every thing is OK.
Anyone can explain for me,and how to insert a record to Access database ? thanks.
the full code:
/////////////////////////////////////////////////
bool result = false;
//OLEDB
OleDbConnection dbConnection = new System.Data.OleDb.OleDbConnection(CfgKeyOleConnString+CfgKeyOleDatabase);
string strSQL = "INSERT INTO Users (UserName,Name,UserPassword,Email,RoleID) VALUES (@UserName,@Name,@UserPassword,@Email,@RoleID)";
OleDbCommand dbComm = new OleDbCommand(strSQL,dbConnection);
dbComm.Parameters.Add(new OleDbParameter ("@UserName", OleDbType.VarChar, 50));
dbComm.Parameters["@UserName"].Value = userName;
dbComm.Parameters.Add(new OleDbParameter ("@Name", OleDbType.VarChar, 50));
dbComm.Parameters["@Name"].Value = displayName;
dbComm.Parameters.Add(new OleDbParameter ("@UserPassword", OleDbType.VarChar, 50));
dbComm.Parameters["@UserPassword"].Value = userPassword;
dbComm.Parameters.Add(new OleDbParameter ("@Email", OleDbType.VarChar, 50));
dbComm.Parameters["@Email"].Value = userEmail;
dbComm.Parameters.Add(new OleDbParameter ("@RoleID", OleDbType.Numeric , 8));
dbComm.Parameters["@RoleID"].Value = Convert.ToInt32(Role);
try
{
dbConnection.Open();
dbComm.ExecuteNonQuery();
result = true;
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
result = false;
}
finally
{
if (dbConnection.State==ConnectionState.Open)
dbConnection.Close();
}
return result;
...NLD...
|
|
|
|
|
The OleDb data provider does not use named parameters. Instead, it uses question marks as placeholders.
string strSQL = "INSERT INTO Users (UserName,Name,UserPassword,Email,RoleID) VALUES (?, ?, ?, ?, ?)";
Obviously, you need to make sure your parameters are added in the correct order.
Charlie
if(!curlies){ return; }
|
|
|
|
|
Anybody familiar with how to set Socket Options, specifically DontFragment?
I've tried the following lines and get the following error messages:
<br />
Socket s = new Socket(IPEP.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);<br />
s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontFragment, true);<br />
Error: optionValue
<br />
Socket s = new Socket(IPEP.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);<br />
s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontFragment, 1);<br />
Error: An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call
I haven't been able to google any working examples, and MSDN is suprisingly general.
Thanks for your help!
|
|
|
|
|
I had the same fun trying to stop one of the base web services classes from sending a fragmented POST to the server... I found no resolution I didnt get any errors though, but from viewing packet captures i could see no matter what, it still was fragmented...
top secret Download xacc-ide 0.0.3 now! See some screenshots
|
|
|
|
|
It's fairly gratifying to know that my programming skills are maturing to the point that I'm asking questions people don't know the answer to.
|
|
|
|
|
I’ve implemented a GUI for a tabletop device using C# and the .NET framework 1.1. At the moment, my interface consists of a collection of virtual sheets of paper in which you can draw. Those documents can be rotated and moved. For the first prototype, I implemented all the graphics by myself in the code. But now I have to reengineer this system in order to add functions. I’m planning to use the standard components, like buttons, textbox, panels, etc. Then, as the second step, I will use activeX, video players, PowerPoint documents, Excel documents etc. Of course, all those things should rotate as well.
So, the question is: Can I extend components, or forms (or generic Windows components...), in order to rotate them? As to as I now, it seems to be impossible to change the orientation of a Component’s ClipRectangle in C#, even if it’s only possible to rotate their graphic interface.
Are there some MS developers who can help me?
Here is the video of the first prototype:
CHILpromo_small.avi
|
|
|
|
|