473,897 Members | 2,991 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C#, SQL-DMO, Add FileGroup Issue.

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(fr mMyForm 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 *,myGetConfigDa ta.OlapUserLogi n*,myGetConfigD ata.OlapUserPas sw*ord);

MyDBDbName.Name =
myConnectionDat a.OlapDatabaseN *ame.ToString() .Trim();
MyDBDataGroup.N ame = "DBDataGrou p";
MyDBDbName.File Groups.Add (MyDBDataGroup) ;
MyDBDataFile.Na me = "DBData";
MyDBDataFile.Ph ysicalName =
myConnectionDat a.OlapDBDataPat *h.ToString().T rim() + @"\DBData.nd f";
MyDBDataFile.Si ze = 50;
MyDBDataFile.Ma ximumSize = -1;
MyDBDataFile.Fi leGrowth = 5;
MyDBDataFile.Fi leGrowthType = 0;
MyDBDataFile.Pr imaryFile = false;
MyDBDbName.File Groups.Item("DB *DataGroup").DB Files.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.

Jul 23 '05 #1
14 4059
Hi

Have you run profiler to see what it is doing at the database end?

John

"LineVoltageHal ogen" <tr************ ****@yahoo.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.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(fr mMyForm 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 *,myGetConfigDa ta.OlapUserLogi n*,myGetConfigD ata.OlapUserPas sw*ord);

MyDBDbName.Name =
myConnectionDat a.OlapDatabaseN *ame.ToString() .Trim();
MyDBDataGroup.N ame = "DBDataGrou p";
MyDBDbName.File Groups.Add (MyDBDataGroup) ;
MyDBDataFile.Na me = "DBData";
MyDBDataFile.Ph ysicalName =
myConnectionDat a.OlapDBDataPat *h.ToString().T rim() + @"\DBData.nd f";
MyDBDataFile.Si ze = 50;
MyDBDataFile.Ma ximumSize = -1;
MyDBDataFile.Fi leGrowth = 5;
MyDBDataFile.Fi leGrowthType = 0;
MyDBDataFile.Pr imaryFile = false;
MyDBDbName.File Groups.Item("DB *DataGroup").DB Files.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.
Jul 23 '05 #2
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_srvrolemembe r(N'sysadmin'), @dbrole,
N'InstanceName' = convert(sysname , serverproperty( N'instancename' )),
N'PID' = convert(int, serverproperty( N'processid'))
from master..spt_val ues v,master..spt_v alues 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

Jul 23 '05 #3
LineVoltageHalo gen (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****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #4
I am connecting as "sa" who is the owner of the database.

Jul 23 '05 #5

"LineVoltageHal ogen" <tr************ ****@yahoo.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.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.N ame = "DBDataGrou p";
MyDBDbName.File Groups.Add (MyDBDataGroup) ;

You probably need this:

MyDBDataGroup.N ame = "DBDataGrou p";
MySQLServerName .Databases(MyDB DbName.Name).Fi leGroups.Add(My DBDataGroup);

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.File Groups.Item("DB *DataGroup").DB Files.Ad (MyDBDataFile);

Try this:

MySQLServerName .Databases(MyDB DbName.Name).Fi leGroups("DB*Da taGroup").DBFil es.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('SQLD MO.SQLServer2')
fg = win32com.client .Dispatch('SQLD MO.FileGroup')
f = win32com.client .Dispatch('SQLD MO.DBFile')

srv.Name = 'kilkenny'
srv.LoginSecure = True
srv.Connect()

fg.Name = 'NewFileGroup'

srv.Databases(' Development').F ileGroups.Add(f g)

f.Name = 'NewDataFile'
f.PhysicalName = 'D:\MSSQL\Data\ NewDataFile.ndf '
f.Size = 50
f.MaximumSize = -1
f.FileGrowth = 5
f.FileGrowthTyp e = 0
f.PrimaryFile = False

srv.Databases(' Development').F ileGroups('NewF ileGroup').DBFi les.Add(f)

srv.Disconnect( )
Jul 23 '05 #6
Simon, thanks for the feedback. However, when I ran the code it
tripped on the following two lines:

MySQLServerName .Databases(MyDB *DbName.Name).F ileGroups.Add(M y*DBDataGroup);

MySQLServerName .Databases(MyDB *DbName.Name).F ileGroups("DB*D a*taGroup").DBF iles.Add
(MyDBDataFile);

The error message was:

'SQLDMO._SQLSer ver.Databases' denotes a 'property' where a 'method' was
expected

Any ideas?

TFD

Jul 23 '05 #7

"LineVoltageHal ogen" <tr************ ****@yahoo.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Simon, thanks for the feedback. However, when I ran the code it
tripped on the following two lines:

MySQLServerName .Databases(MyDB *DbName.Name).F ileGroups.Add(M y*DBDataGroup);

MySQLServerName .Databases(MyDB *DbName.Name).F ileGroups("DB*D a*taGroup").DBF iles.Add
(MyDBDataFile);

The error message was:

'SQLDMO._SQLSer ver.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.SQLServe r2 srv = new SQLDMO.SQLServe r2();
SQLDMO.FileGrou p2 fg = new SQLDMO.FileGrou p2();
SQLDMO._Databas e db = new SQLDMO.Database ();
SQLDMO.DBFile f = new SQLDMO.DBFile() ;

srv.Name = "kilkenny";
srv.LoginSecure = true;
srv.Connect(nul l,null,null);

fg.Name = "NewFileGro up";
db = srv.Databases.I tem("Developmen t", null);
db.FileGroups.A dd(fg);

f.Name = "NewDataFil e";
f.PhysicalName = @"D:\MSSQL\Data \NewFile.ndf";
f.Size = 50;
f.MaximumSize = -1;
f.FileGrowth = 5;
f.FileGrowthTyp e = 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
Jul 23 '05 #8
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

Jul 23 '05 #9
Simon, why did you switch to SQLDMO.SQLSERVE R2 and two for the other
object types?

TFD

Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3362
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 about sql database and sql server, specially this article: http://www.aspfaq.com/show.asp?id=2195 will someone help me understand: 1. with *SQL Server*, do i keep my current Access 2000 database and ASP pages?
2
12671
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 ${SCHEMA_NM}/${SCHEMA_PASSWD}@${DB_NM} <<-ANALYZE_TABLE SET TERMOUT ON
0
10239
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 database table, using dynamic sql. Executing 'EXEC SQL DESCRIBE SELECT LIST FOR S INTO select_dp;' the error code -2149 is returned That means "Specified partition does not exist". Does anybody know if it is a database problem or a problem of
2
15243
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 Personal disk from the SQL Server 2000 Enterprise kit as this is reported here on the MSDN web site to be the version that is supported on Windows XP. In fact so many of you kind people confess to having succeeded in doing it. I have tried...
1
6650
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 Express Edition x86: Component Microsoft SQL Server 2005 Express Edition x86 returned an unexpected value. ***EndOfSession***? Microsoft SQL Server 2005 Express Edition x86: Component Microsoft SQL Server 2005 Express Edition x86 returned an...
2
6991
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 attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
6
2511
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 stored in the .py files and run in the .cgi files. I have the problem that I need to construct a row from two seprate SQL Querys, I have tried combining the two Querys but all that does is create a Query that returns nothing after a long period...
14
3054
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 anyone please help me with this as I want to install SQL server and also wouold be grateful, if you can suggest me any workaround to dealwith this problem.(Like should I install any new OS etc). Any help would be appreciated.
5
9296
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 records from an external Oracle source using a SQL statement. The SQL statement works as expected when the loop code is commented out, but I receive an error "SQL command not properly ended" when the loop is active. Do Until intLoop = UserNum ...
0
10850
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10941
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9656
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8032
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7185
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5873
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4698
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4293
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3300
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.