Greetings All, I was hoping that someone might be able to shed some
light on this issue. I am trying to add a FileGroup/Datafile to an
existing SQL database. The code below compile and it runs in .NET
Studio, however nothing happens? The form closes, no error messages
are thrown, there is no sign of any type of error taking place. The
end result (assuming the code is correct) is tha there should be a new
FileGroup with a datafile in it, here is the code:
************************************************** ******************
private void AddFileGroup(frmMyForm f)
{
SQLMy.SQLServer MySQLServerName = new SQLMy.SQLServer();
SQLMy.Database MyDBDbName = new SQLMy.Database();
SQLMy.FileGroup MyDBDataGroup = new SQLMy.FileGroup();
SQLMy.DBFile MyDBDataFile = new SQLMy.DBFile();
try
{
MySQLServerName.Connect
myGetConfigData.OlapServerName*,myGetConfigData.Ol apUserLogin*,myGetConfigData.OlapUserPassw*ord);
MyDBDbName.Name =
myConnectionData.OlapDatabaseN*ame.ToString().Trim ();
MyDBDataGroup.Name = "DBDataGroup";
MyDBDbName.FileGroups.Add (MyDBDataGroup);
MyDBDataFile.Name = "DBData";
MyDBDataFile.PhysicalName =
myConnectionData.OlapDBDataPat*h.ToString().Trim() + @"\DBData.ndf";
MyDBDataFile.Size = 50;
MyDBDataFile.MaximumSize = -1;
MyDBDataFile.FileGrowth = 5;
MyDBDataFile.FileGrowthType = 0;
MyDBDataFile.PrimaryFile = false;
MyDBDbName.FileGroups.Item("DB*DataGroup").DBFiles .Ad (MyDBDataFile);
this.Close();
MySQLServerName.DisConnect();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
finally
{
MySQLServerName.DisConnect();
}
}
************************************************** ******************
Note: myGetConfigData: This is a class that reads in the values for the
db connection from an XML file. This class has been tested extensively
and the data values are being populated into the variables.
I would appreciate any help that anyone might be able to provide to me.
Regards, TFD. 14 4023
Hi
Have you run profiler to see what it is doing at the database end?
John
"LineVoltageHalogen" <tr****************@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Greetings All, I was hoping that someone might be able to shed some
light on this issue. I am trying to add a FileGroup/Datafile to an
existing SQL database. The code below compile and it runs in .NET
Studio, however nothing happens? The form closes, no error messages
are thrown, there is no sign of any type of error taking place. The
end result (assuming the code is correct) is tha there should be a new
FileGroup with a datafile in it, here is the code:
************************************************** ******************
private void AddFileGroup(frmMyForm f)
{
SQLMy.SQLServer MySQLServerName = new SQLMy.SQLServer();
SQLMy.Database MyDBDbName = new SQLMy.Database();
SQLMy.FileGroup MyDBDataGroup = new SQLMy.FileGroup();
SQLMy.DBFile MyDBDataFile = new SQLMy.DBFile();
try
{
MySQLServerName.Connect
myGetConfigData.OlapServerName*,myGetConfigData.Ol apUserLogin*,myGetConfigData.OlapUserPassw*ord);
MyDBDbName.Name =
myConnectionData.OlapDatabaseN*ame.ToString().Trim ();
MyDBDataGroup.Name = "DBDataGroup";
MyDBDbName.FileGroups.Add (MyDBDataGroup);
MyDBDataFile.Name = "DBData";
MyDBDataFile.PhysicalName =
myConnectionData.OlapDBDataPat*h.ToString().Trim() + @"\DBData.ndf";
MyDBDataFile.Size = 50;
MyDBDataFile.MaximumSize = -1;
MyDBDataFile.FileGrowth = 5;
MyDBDataFile.FileGrowthType = 0;
MyDBDataFile.PrimaryFile = false;
MyDBDbName.FileGroups.Item("DB*DataGroup").DBFiles .Ad (MyDBDataFile);
this.Close();
MySQLServerName.DisConnect();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
finally
{
MySQLServerName.DisConnect();
}
}
************************************************** ******************
Note: myGetConfigData: This is a class that reads in the values for the
db connection from an XML file. This class has been tested extensively
and the data values are being populated into the variables.
I would appreciate any help that anyone might be able to provide to me.
Regards, TFD.
I used Lumigents Entegra to trace the action. There is only one call
to the table: master.dbo.spt_values, here is the complete text:
************************************************** ************************************************** ******************
-- sp_MSdbuserpriv
select @@version, N'login_id' = convert(int, suser_sid()), N'pagesize'
= v.low, N'highbit' = v2.low, N'highbyte' = v3.low,
N'casesens' = (case when (N'A' != N'a') then 1 else 0 end), @@spid,
convert(sysname, serverproperty(N'servername')),
is_srvrolemember(N'sysadmin'), @dbrole,
N'InstanceName' = convert(sysname, serverproperty(N'instancename')),
N'PID' = convert(int, serverproperty(N'processid'))
from master..spt_values v,master..spt_values v2,master..spt_values v3
where v.number=1 and v.type=N'E' and v2.number=2
and v2.type=N'E' and v3.number=3 and v3.type=N'E'
************************************************** ************************************************** *******************
So, it looks like the connection is being made but the command to
create the filegroup/datafile is never being issued?
TFD
LineVoltageHalogen (tr****************@yahoo.com) writes: I used Lumigents Entegra to trace the action. There is only one call to the table: master.dbo.spt_values, here is the complete text:
-- sp_MSdbuserpriv
Given the name of the procedure, I could be that you fail a permission
check. What priviledges do the user you connect with have?
Why you don't an exception raised I don't know, but DMO might
communicate errors by other means. (I don't know DMO myself.)
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp
I am connecting as "sa" who is the owner of the database.
"LineVoltageHalogen" <tr****************@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Greetings All, I was hoping that someone might be able to shed some
light on this issue. I am trying to add a FileGroup/Datafile to an
existing SQL database. The code below compile and it runs in .NET
Studio, however nothing happens? The form closes, no error messages
are thrown, there is no sign of any type of error taking place. The
end result (assuming the code is correct) is tha there should be a new
FileGroup with a datafile in it, here is the code:
<snip>
The problem seems to be the way you're using the Database object - it looks
like you've instantiated a database object, but a database object by itself
has nothing to do with a server. So instead of this:
MyDBDataGroup.Name = "DBDataGroup";
MyDBDbName.FileGroups.Add (MyDBDataGroup);
You probably need this:
MyDBDataGroup.Name = "DBDataGroup";
MySQLServerName.Databases(MyDBDbName.Name).FileGro ups.Add(MyDBDataGroup);
Similarly, when you add the file, instead of this (by the way, you have Ad,
not Add, but I guess that's a copy and paste error):
MyDBDbName.FileGroups.Item("DB*DataGroup").DBFiles .Ad (MyDBDataFile);
Try this:
MySQLServerName.Databases(MyDBDbName.Name).FileGro ups("DB*DataGroup").DBFiles.Add
(MyDBDataFile);
In fact, in this case you don't need a database object at all - normally you
only need to instantiate a SQLDMO object when you're creating a completely
new one. To work with an existing object, you just get a reference to it
from the relevant collection on the server. The script below is a Python
version of what you're trying to do - it might make this clearer.
Simon
import win32com.client
srv = win32com.client.Dispatch('SQLDMO.SQLServer2')
fg = win32com.client.Dispatch('SQLDMO.FileGroup')
f = win32com.client.Dispatch('SQLDMO.DBFile')
srv.Name = 'kilkenny'
srv.LoginSecure = True
srv.Connect()
fg.Name = 'NewFileGroup'
srv.Databases('Development').FileGroups.Add(fg)
f.Name = 'NewDataFile'
f.PhysicalName = 'D:\MSSQL\Data\NewDataFile.ndf'
f.Size = 50
f.MaximumSize = -1
f.FileGrowth = 5
f.FileGrowthType = 0
f.PrimaryFile = False
srv.Databases('Development').FileGroups('NewFileGr oup').DBFiles.Add(f)
srv.Disconnect()
Simon, thanks for the feedback. However, when I ran the code it
tripped on the following two lines:
MySQLServerName.Databases(MyDB*DbName.Name).FileGr oups.Add(My*DBDataGroup);
MySQLServerName.Databases(MyDB*DbName.Name).FileGr oups("DB*Da*taGroup").DBFiles.Add
(MyDBDataFile);
The error message was:
'SQLDMO._SQLServer.Databases' denotes a 'property' where a 'method' was
expected
Any ideas?
TFD
"LineVoltageHalogen" <tr****************@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Simon, thanks for the feedback. However, when I ran the code it
tripped on the following two lines:
MySQLServerName.Databases(MyDB*DbName.Name).FileGr oups.Add(My*DBDataGroup);
MySQLServerName.Databases(MyDB*DbName.Name).FileGr oups("DB*Da*taGroup").DBFiles.Add
(MyDBDataFile);
The error message was:
'SQLDMO._SQLServer.Databases' denotes a 'property' where a 'method' was
expected
Any ideas?
TFD
I don't know much about C#, but a combination of brute force and ignorance
produced this code, which does work correctly. It seems C# is not as happy
as Python or VBScript to reference objects in the way I suggested earlier,
so a Database object is probably needed after all - apologies for the
misleading response:
SQLDMO.SQLServer2 srv = new SQLDMO.SQLServer2();
SQLDMO.FileGroup2 fg = new SQLDMO.FileGroup2();
SQLDMO._Database db = new SQLDMO.Database();
SQLDMO.DBFile f = new SQLDMO.DBFile();
srv.Name = "kilkenny";
srv.LoginSecure = true;
srv.Connect(null,null,null);
fg.Name = "NewFileGroup";
db = srv.Databases.Item("Development", null);
db.FileGroups.Add(fg);
f.Name = "NewDataFile";
f.PhysicalName = @"D:\MSSQL\Data\NewFile.ndf";
f.Size = 50;
f.MaximumSize = -1;
f.FileGrowth = 5;
f.FileGrowthType = 0;
f.PrimaryFile = false;
fg.DBFiles.Add(f);
srv.DisConnect();
For some reason, this declaration doesn't work, hence the underscore in the
version above:
SQLDMO.Database db = new SQLDMO.Database();
This is just C# ignorance on my part, so I don't know if it's something to
worry about or not.
Simon
Thanks Simon, I will try what you say. On another note do you know of
any good references for SQL-DMO?
I have Mitchell's book but it is for VB and not C#. MSDN only has info
for VB, C or C++ and not C#!
TFD
Simon, why did you switch to SQLDMO.SQLSERVER2 and two for the other
object types?
TFD
Simon, you ROCK! That worked! I am extremely gratefull to you.
TFD
"LineVoltageHalogen" <tr****************@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com... Simon, why did you switch to SQLDMO.SQLSERVER2 and two for the other object types?
TFD
No particular reason - in this case it doesn't matter, but it others it may,
so I generally use the extended objects if there is one.
As for resources, I've only ever used Books Online (and Google, of course).
I usually work with SQLDMO in Python and VBScript, and it isn't too hard to
use VB code as an example.
Simon
Simon, one quick question. Does the Java programming language support
SQL-DMO? I was thinking that if I wanted to convert my c# program to
J2EE could it be done?
TFD
No idea. If you can access COM objects from Java, then I don't see why
not, but I don't know how you would do that.
In any case, I'm not sure what the point would be - anyone running
MSSQL must be running Windows, so there's not much benefit to a Java
version. Even if an organization uses Java on Unix/Linux for business
applications with an MSSQL backend, the MSSQL DBAs will still be using
Windows, and SQLDMO is most useful for them.
You might also consider that the SQL2005 version of SQLDMO - SMO - is a
..NET assembly, not a COM object, so .NET is the way to go if you intend
to support SQL2005 at some future point.
Simon
Good points, all of them.
As a side note I managed to finish my application entirely in C#. I
was hard not having any examples and not being a programmer. All the
VB examples out there helped quite and bit as well as your input.
Thanks Again, TFD. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: cooldv |
last post by:
i am running a website on Windows 2000 server with ASP 3 webpages and
Access 2000 database. (with a hosting company)
traffic is slow at this time but expect to grow. lately i have been
reading...
|
by: Peter |
last post by:
I run most of my SQL scripts via kornshell on AIX.
I use the "here-document" to run some of the smaller ones.
Example:
#!/bin/ksh
# Analyze the table.
sqlplus...
|
by: Jan |
last post by:
I store sql-commands in a database table. In the first step I get the
sql command out of the database table with embedded sql. In the second
step I try to execute the command, which i got from the...
|
by: Ken Lindner |
last post by:
I have a need to become familiar with SQL Server 2000 for work.
Needless to say I am new to SQL Server any version, but not IT in
general. My employer has provided me with the SQL Server 2000...
|
by: Peter |
last post by:
I've purchased VS.NET 2005 Standard and have tried to install SQL Server
2005 Express, but get the following error in the error log.
Please could someone help me....
Microsoft SQL Server 2005...
|
by: Jobs |
last post by:
Download the JAVA , .NET and SQL Server interview with answers
Download the JAVA , .NET and SQL Server interview sheet and rate
yourself. This will help you judge yourself are you really worth of...
|
by: Fuzzydave |
last post by:
I am back developing futher our Python/CGI based web application run by
a Postgres DB
and as per usual I am having some issues. It Involves a lot of Legacy
code. All the actual
SQL Querys are...
|
by: Developer |
last post by:
Hello All,
i have recently installed VS2005 and was trying to install SQL sever
2000.
I have Win XP' SP2. But when I tried installing, it only installed
client tools and not the database.
Can...
|
by: dbrother |
last post by:
Access 2003 Win XP Pro SP3
Using SQL /ADO Recordsets in a Do Loop
Hello,
I'm using a random number generator based on an integer input from a user from a form that will get X number of random...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| | |