Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
muhssamy
Resolver I
Resolver I

Connect Spark

in the documentation overview 

it is mentioned that i can create and manage my data in sql database using spark

can anyone help me how to do this ?

 

muhssamy_0-1732685983850.png

 

1 ACCEPTED SOLUTION
muhssamy
Resolver I
Resolver I

Thanks All 
i authorized using service principle using the following

jdbc_url = (
    "jdbc:sqlserver://<your-server-name>.database.windows.net:1433;"
    "database=<your-database-name>;"
    "authentication=ActiveDirectoryServicePrincipal;"
    "encrypt=true;"
    "trustServerCertificate=true;"
)
sql_db_options = {
    "url": jdbc_url,
    "dbtable": "<your-table-name>",
    "user": "<service-principal-client-id>",
    "password": "<service-principal-client-secret>"
}
df = spark.read.format("jdbc").options(**sql_db_options).load()
df.show()

View solution in original post

8 REPLIES 8
g3kuser
Helper I
Helper I

Hi,

 

I want to connect using Workspace Space Identity and was wondering how to achieve it from notebook given I don't get to see the secret for the identity created? 

 

Thanks,

 

Gayatri

muhssamy
Resolver I
Resolver I

Thanks All 
i authorized using service principle using the following

jdbc_url = (
    "jdbc:sqlserver://<your-server-name>.database.windows.net:1433;"
    "database=<your-database-name>;"
    "authentication=ActiveDirectoryServicePrincipal;"
    "encrypt=true;"
    "trustServerCertificate=true;"
)
sql_db_options = {
    "url": jdbc_url,
    "dbtable": "<your-table-name>",
    "user": "<service-principal-client-id>",
    "password": "<service-principal-client-secret>"
}
df = spark.read.format("jdbc").options(**sql_db_options).load()
df.show()
Poojara_D12
Super User
Super User

Hi @muhssamy 

To create and manage your data in a SQL database using Spark within Microsoft Fabric:

  1. Set up a Spark Cluster: First, create a Spark cluster in your Fabric workspace.

  2. Use Notebooks for Data Engineering: Open a notebook in Fabric and use PySpark or Spark SQL to connect to your SQL database.

  3. Data Management: Use Spark to perform operations like loading data, transforming it, and writing back to your SQL database. Here's a simple example:

 

# Example PySpark code to read from SQL and write to Spark DataFrame
jdbc_url = "jdbc:sqlserver://<server_name>:<port>;databaseName=<db_name>"
properties = {"user": "<username>", "password": "<password>", "driver": "com.microsoft.sqlserver.jdbc.SQLServerDriver"}

# Load data from SQL Server
sql_df = spark.read.jdbc(url=jdbc_url, table="<your_table>", properties=properties)

# Perform transformation using Spark
transformed_df = sql_df.filter(sql_df["column_name"] > 100)

# Write data back to SQL
transformed_df.write.jdbc(url=jdbc_url, table="<new_table>", mode="overwrite", properties=properties)

4. Design Pipelines: Use Fabric's Data Engineering pipelines to automate data movement from your SQL database to Spark and back.

 

By following these steps, you can efficiently manage and process your SQL database data using Spark in Fabric.

 

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Poojara
Data Analyst | MSBI Developer | Power BI Consultant
Please Subscribe my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS  (360 remaining for 500 SUBS) Please support!!

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos"

Kind Regards,
Poojara - Proud to be a Super User
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS

Hi @Poojara_D12 Getting the error as "Spark_Ambiguous_JDBC_SQLServerException" 

karthikvalluri_0-1737705154483.png

How to resolve this?

the problem here what is the user name and passoword
there is no sql user for this database

muhssamy_0-1732698067181.png

 

Hello @muhssamy 

The username is your account that sign in the fabric, and the password is the password is the your account password that sign in the fabric, you can see your server name and database name in settings of database. click the settings icon in home tab.

vxinruzhumsft_0-1732762246818.png

 Then click the connection strings, in this tab, it offers different strings of the data connection.

vxinruzhumsft_1-1732762270393.png

e.g You can click the php, then it will dislay your server information.

vxinruzhumsft_2-1732762520525.png

You can refer to the following link to know more.

Connect to your SQL database - Microsoft Fabric | Microsoft Learn

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

will this work with Account with MFA ?

Hi @muhssamy 

Yes, after testing it can work for Account with MFA, but you need to configure the access for the account.

You can refer to the following link.

Authorization in SQL database - Microsoft Fabric | Microsoft Learn

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
MarchFBCvideo - carousel

Fabric Monthly Update - March 2025

Check out the March 2025 Fabric update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.

"); $(".slidesjs-pagination" ).prependTo(".pagination_sec"); $(".slidesjs-pagination" ).append("
"); $(".slidesjs-play.slidesjs-navigation").appendTo(".playpause_sec"); $(".slidesjs-stop.slidesjs-navigation").appendTo(".playpause_sec"); $(".slidesjs-pagination" ).append(""); $(".slidesjs-pagination" ).append(""); } catch(e){ } /* End: This code is added by iTalent as part of iTrack COMPL-455 */ $(".slidesjs-previous.slidesjs-navigation").attr('tabindex', '0'); $(".slidesjs-next.slidesjs-navigation").attr('tabindex', '0'); /* start: This code is added by iTalent as part of iTrack 1859082 */ $('.slidesjs-play.slidesjs-navigation').attr('id','playtitle'); $('.slidesjs-stop.slidesjs-navigation').attr('id','stoptitle'); $('.slidesjs-play.slidesjs-navigation').attr('role','tab'); $('.slidesjs-stop.slidesjs-navigation').attr('role','tab'); $('.slidesjs-play.slidesjs-navigation').attr('aria-describedby','tip1'); $('.slidesjs-stop.slidesjs-navigation').attr('aria-describedby','tip2'); /* End: This code is added by iTalent as part of iTrack 1859082 */ }); $(document).ready(function() { if($("#slides .item").length < 2 ) { /* Fixing Single Slide click issue (commented following code)*/ // $(".item").css("left","0px"); $(".item.slidesjs-slide").attr('style', 'left:0px !important'); $(".slidesjs-stop.slidesjs-navigation").trigger('click'); $(".slidesjs-previous").css("display", "none"); $(".slidesjs-next").css("display", "none"); } var items_length = $(".item.slidesjs-slide").length; $(".slidesjs-pagination-item > button").attr("aria-setsize",items_length); $(".slidesjs-next, .slidesjs-pagination-item button").attr("tabindex","-1"); $(".slidesjs-pagination-item button").attr("role", "tab"); $(".slidesjs-previous").attr("tabindex","-1"); $(".slidesjs-next").attr("aria-hidden","true"); $(".slidesjs-previous").attr("aria-hidden","true"); $(".slidesjs-next").attr("aria-label","Next"); $(".slidesjs-previous").attr("aria-label","Previous"); //$(".slidesjs-stop.slidesjs-navigation").attr("role","button"); //$(".slidesjs-play.slidesjs-navigation").attr("role","button"); $(".slidesjs-pagination").attr("role","tablist").attr("aria-busy","true"); $("li.slidesjs-pagination-item").attr("role","list"); $(".item.slidesjs-slide").attr("tabindex","-1"); $(".item.slidesjs-slide").attr("aria-label","item"); /*$(".slidesjs-stop.slidesjs-navigation").on('click', function() { var itemNumber = parseInt($('.slidesjs-pagination-item > a.active').attr('data-slidesjs-item')); $($('.item.slidesjs-slide')[itemNumber]).find('.c-call-to-action').attr('tabindex', '0'); });*/ $(".slidesjs-stop.slidesjs-navigation, .slidesjs-pagination-item > button").on('click keydown', function() { $.each($('.item.slidesjs-slide'),function(i,el){ $(el).find('.c-call-to-action').attr('tabindex', '-1'); }); var itemNumber = parseInt($('.slidesjs-pagination-item > button.active').attr('data-slidesjs-item')); $($('.item.slidesjs-slide')[itemNumber]).find('.c-call-to-action').attr('tabindex', '0'); }); $(".slidesjs-play.slidesjs-navigation").on('click', function() { $.each($('.item.slidesjs-slide'),function(i,el){ $(el).find('.c-call-to-action').attr('tabindex', '-1'); }); }); $(".slidesjs-pagination-item button").keyup(function(e){ var keyCode = e.keyCode || e.which; if (keyCode == 9) { e.preventDefault(); $(".slidesjs-stop.slidesjs-navigation").trigger('click').blur(); $("button.active").focus(); } }); $(".slidesjs-play").on("click",function (event) { if (event.handleObj.type === "click") { $(".slidesjs-stop").focus(); } else if(event.handleObj.type === "keydown"){ if (event.which === 13 && $(event.target).hasClass("slidesjs-play")) { $(".slidesjs-stop").focus(); } } }); $(".slidesjs-stop").on("click",function (event) { if (event.handleObj.type === "click") { $(".slidesjs-play").focus(); } else if(event.handleObj.type === "keydown"){ if (event.which === 13 && $(event.target).hasClass("slidesjs-stop")) { $(".slidesjs-play").focus(); } } }); $(".slidesjs-pagination-item").keydown(function(e){ switch (e.which){ case 37: //left arrow key $(".slidesjs-previous.slidesjs-navigation").trigger('click'); e.preventDefault(); break; case 39: //right arrow key $(".slidesjs-next.slidesjs-navigation").trigger('click'); e.preventDefault(); break; default: return; } $(".slidesjs-pagination-item button.active").focus(); }); }); // Start This code is added by iTalent as part of iTrack 1859082 $(document).ready(function(){ $("#tip1").attr("aria-hidden","true").addClass("hidden"); $("#tip2").attr("aria-hidden","true").addClass("hidden"); $(".slidesjs-stop.slidesjs-navigation, .slidesjs-play.slidesjs-navigation").attr('title', ''); $("a#playtitle").focus(function(){ $("#tip1").attr("aria-hidden","false").removeClass("hidden"); }); $("a#playtitle").mouseover(function(){ $("#tip1").attr("aria-hidden","false").removeClass("hidden"); }); $("a#playtitle").blur(function(){ $("#tip1").attr("aria-hidden","true").addClass("hidden"); }); $("a#playtitle").mouseleave(function(){ $("#tip1").attr("aria-hidden","true").addClass("hidden"); }); $("a#play").keydown(function(ev){ if (ev.which ==27) { $("#tip1").attr("aria-hidden","true").addClass("hidden"); ev.preventDefault(); return false; } }); $("a#stoptitle").focus(function(){ $("#tip2").attr("aria-hidden","false").removeClass("hidden"); }); $("a#stoptitle").mouseover(function(){ $("#tip2").attr("aria-hidden","false").removeClass("hidden"); }); $("a#stoptitle").blur(function(){ $("#tip2").attr("aria-hidden","true").addClass("hidden"); }); $("a#stoptitle").mouseleave(function(){ $("#tip2").attr("aria-hidden","true").addClass("hidden"); }); $("a#stoptitle").keydown(function(ev){ if (ev.which ==27) { $("#tip2").attr("aria-hidden","true").addClass("hidden"); ev.preventDefault(); return false; } }); }); // End This code is added by iTalent as part of iTrack 1859082
Top Solution Authors
Top Kudoed Authors